Trying to use the "read command" to accept user input from the command prompt itself but my script doesnt seem to be moving forward
echo "Do you want to continue?(yes/no)" read -p $1 if [ "$1" == "yes" ] then sleep 5s echo "" echo " move ahead" else echo "" echo "Skipping The Step.." echo "" sleep 5s fi
I want to execute the script like this..
sh script.sh yes sh script.sh no
Added a -p to the above script and all seems to work very well. This is my real problem. I have another script test.sh which calls script.sh. So this is how i put the input
cat test.sh yes #!/bin/bash echo "execute the below script" sh script.sh $1 sh test.sh yes
This way doesnt work as the script picks up a default no and moves ahead. Any ideas.
-p
argument doesn't even allow the user to change the answer.bash
is notsh
.bash
is the GNU implementation of ash
interpreter, but there are many other different implementations.read -p
is not valid standardsh
syntax. Those differentsh
implementations will treat it differently. Check here for thesh
language specification, and specifically for theread
utility.