-1

I trying to run script1.sh from script2.sh and answer script 1's prompts.

In script1.sh:

echo "Do you wish to save these settings?"
read response
if [ $response = "yes" ]
then 
   echo "Settings saved"
elif [ $response = "no" ]
then 
   echo "Settings not saved"
fi
echo "Would like to end"
read response2
if [ $response2 = "yes" ]
then 
   echo "Bye"
elif [ $response2 = "no" ]
then 
   echo "OK"
fi

In script2.sh:

sh "/home/username/Desktop/script1.sh"

I want it so that whenever i try to run script2.sh, it would automatically enter yes or no for both prompts for script1.sh.

  • 1
    A much better design (which would make your original question title correct, though I see somebody updated it now) is to pass the options as command-line parameters instead. – tripleee May 04 '19 at 09:09

1 Answers1

0

I have an sugestion:

In script1.sh:

echo "Do you wish to save these settings?"
read response
while [ "$response" != "yes" ] && [ "$response" != "no" ] 
do
  echo "Please enter yes or no only"
  echo "Do you wish to save these settings?"
  read response 
done

In script2.sh:

source "/home/username/Desktop/script1.sh"

or

echo yes | sh "/home/username/Desktop/script1.sh"
Silver
  • 406
  • 2
  • 12