Use a while
loop:
while read -p "Make your selection: " varSelection; do
...
done
and break
appropriately.
Question
I'm trying to use a "case" structure to provide options and "if" to actually perform the actions. I'm very very new in scripting so please forgive my lack of knowledge. To simplify things, I will skip any comments in the code and only use 1 (one) of the options for this script.
#!/bin/sh
echo " 01. Select a new hostname"
read -p "Make your selection: " varSelection
case $varSelection in
1)
read -p "$(echo -e 'Enter hostname here: \n')" varHostName
read -p "¿Are u sure u want to use \" $varHostname \"? (y/n)"varHostNameRight
if [ $varHostNameRight == y ]; then
sed -i "s/^\(HOSTNAME\s*=\s*\).*\$/\1$varHostName/" /etc/sysconfig/network
hostname $varHostName
else
if [ $varHostNameRight == n ]; then
fi
;;
esac
In this example, what I'd like to achive is that if user selects "y" in line "04", after executing lines 6 and 7 he returns to the "case" menu (as actually, there are more options in the case than 1)) I don't know how to do that :S after every option applies in my script, I have to re-run it to select other option.
Also, if user selects "no" in line "04", I would like to "loop" to line "03"...but again, I don't know how to do that :(
Please, any help is more than welcome!
Best regards,
Sebas
Solution
Use a while
loop:
while read -p "Make your selection: " varSelection; do
...
done
and break
appropriately.