Select - use the PS3 prompt
When you login into the bash enviroment you login using the PS1 promt by default
env | grep PS
set | grep PS -> RESULT
GROUPS=()
PS1='[\u@\h\W]\$ ' -> contains info regarding the username, host and working direcotry
PS2='> '
PS4='+ '
When you invoke 'select' from the bash script the PS3 will get the default value
nano select.sh
CONTENT OF FILE
#! /bin/bash
PS3='Please select a choice: '
select var in "Var1 Var2"
do
echo Hello World
command
break
done
#END
. select.sh ->result
1) Var1
Helo World
CONTENT OF FILE
#! /bin/bash
PS3='Please select a choice: '
LIST="Var 1 Var2"
select i in $LIST
do
if [ $i = "Var1"]
then
echo Hello World
elif [$i = "Var2"]
then
echo Goodbye World
fi
break
done
#END
CONTENT OF FILE
#! /bin/bash
PS3='Please select a choice: '
LIST="Var 1 Var2 Quit"
select i in $LIST
do
if [ $i = "Var1"]
then
echo Hello World
elif [$i = "Var2"]
then
echo Goodbye World
elif [ $i = "Quit"]
then
exit
fi
# break
done
#END
chmod u+x select.sh
./select.sh -> in this was selecting option 3-Quit we get out of the subshel. When we execute ./select.sh a subshell is created
CONTENT OF FILE
#! /bin/bash
PS3='Please select a choice: '
LIST="MySQL System Quit"
select i in $LIST
do
if [ $i = "MySQL"]
then
clear
watch tail /var/log/mysqld.log
elif [$i = "System"]
then
clear
watch tail /var/log/messages
elif [ $i = "Quit"]
then
exit
fi
# break
done
#END
No comments:
Post a Comment