ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have been having trouble adding an option to the botton of my shell script like so
"Please Choose from the following list of options:"
1. Show the path enviroment varible
2. List all text files under your home directory
3. Show the disk usage for your user home directory
4. Exit
Selection _ ( with a flashing cursor )
I need to have it that if wrong selection is made ( say 5 ) it will print an error & return after two seconds to the selection screen again
Here is the start of my script
clear
echo "Please Choose from the following list of options:"
echo 1. Show the path enviroment varible
echo 2. List all text files under your home directory
echo 3. Show the disk usage for your user home directory
echo 4. Exit
echo "What is your Selection" (how do i put flashing cursor & add error message if wrong button is pressed)
read vvar
if [ ${vvar} -eq 1 ];then
echo "This is what you are bashing"
cat .bash_profile |grep HOME
while [ 1 ]
do
echo "
1. Show the path enviroment varible
2. List all text files under your home directory
3. Show the disk usage for your user home directory
4. Exit"
read hello
case $hello in
1)
;ur code
;;
2)
;ur code
;;
3)
;ur code
;;
*)
;ur code
;;
esac
done
I think u can write ur code for each case .This is perfect sytax for ur code.Bye.
Last edited by paonethestar; 11-04-2003 at 12:11 AM.
What is wrong with the last "fi" statement in this script ?
#!/bin/bash
# this sets the inital stuff
vvar=0
while test ${vvar} != 4; do
clear
echo "Please Choose from the following list of options:"
echo 1. Show the path enviroment varible
echo 2. List all text files under your home directory
echo 3. Show the disk usage for your user home directory
echo 4. Exit
echo ""
read vvar
if [ ${vvar} == 1 ];then
cat .bash_profile |grep HOME
echo "Press any key to continue"
echo ""
read evar #evar empty variable
fi
if [ ${vvar} == 2 ]; then
ls -la *.txt
echo "Press any key to continue"
echo ""
read evar #evar empty variable
fi
if [ ${vvar} == 3 ]; then
du ~/ -s -h
echo "Press any key to continue"
echo ""
read evar #evar empty variable
fi
if [ ${vvar} == 4 ]; then
echo "Thanks for Coming $USER"
exit 0
fi
if [ ${vvar} == * ] then
echo "Sorry, Wrong key pressed.Please choose another option from list"
sleep 2
echo "Press any key to continue"
echo ""
read evar #evar empty variable
fi
done
vvar=1
if [ ${vvar} == 1 ];then
cat .bash_profile |grep HOME
echo "Press any key to continue"
echo ""
read evar #evar empty variable
else if [ ${vvar} == 2 ]; then
ls -la *.txt
echo "Press any key to continue"
echo ""
read evar #evar empty variable
else if [ ${vvar} == 3 ]; then
du ~/ -s -h
echo "Press any key to continue"
echo ""
read evar #evar empty variable
else if [ ${vvar} == 4 ]; then
echo "Thanks for Coming $USER"
exit 0
else
echo "Sorry, Wrong key pressed.Please choose another option from list"
sleep 2
echo "Press any key to continue"
echo ""
read evar #evar empty variable
fi
fi
fi
fi
change ur code to this after reading sentence.Because u can't assign "*" for remaing all other choices like this.It may take it as string or any.With my knowledge i can say that assignment causing prob !.
Last edited by paonethestar; 11-04-2003 at 12:38 AM.
I also posted this in your other post in General Linux forum.
Code:
#!/bin/bash
select program in 'Show the path enviroment varible' \
'List all text files under your home directory' \
'Show the disk usage for your user home directory' \
'Exit'
do
case $REPLY in
1)
#Show the path enviroment varible
echo -e ${PATH//:/\\n}
;;
2)
#List all text files under your home directory
file `find ~/ -type f -maxdepth 1`|grep ASCII
;;
3)
#Show the disk usage for your user home directory
du -s ~/
;;
4)
break
;;
*)
echo "Please select another option from the list"
sleep 2
;;
esac
done
That would be the PS3 variable.
PS3="Please make your selection..."
You probably don't want to export PS3, that way when the script finishes the PS3 will go back to it's normal self.
1. Show the PATH environment variable
2. List all text files under your user home directory
3. Show the disk usage for your user home directory
4. Exit
Selection:
-- (cursor is here)
how can i make it so it is here
1. Show the PATH environment variable
2. List all text files under your user home directory
3. Show the disk usage for your user home directory
4. Exit
Selection: _
I know this is just cosmectic but am interested to know all the same
You need to post that part of your script. For instance using my script and adding the PS3 variable I get this:
1) Show the path enviroment varible
2) List all text files under your home directory
3) Show the disk usage for your user home directory
4) Exit
Selection: _
The cursor is just a block not an underscore.
Code:
#!/bin/bash
PS3="Selection: "
select program in 'Show the path enviroment varible' \
'List all text files under your home directory' \
'Show the disk usage for your user home directory' \
'Exit'
do
...
...
...
done
(apol. in advance mods - also reply in Linux General)
Check out man du ls etc etc etc to fine-tune the options in the functions at the top: - a quick example:
Code:
#!/bin/bash
a() { echo $PATH; }
b() { ls -la; }
c() { du -sh; }
echo ""
echo "Please type either 1 or 2 or 3 for the following respectively:"
echo ""
OPTIONS="PATH ls du"
select opt in $OPTIONS; do
if [ "$opt" = "PATH" ]; then
a;
exit
elif [ "$opt" = "ls" ]; then
b;
exit
elif [ "$opt" = "du" ]; then
c;
exit
else
clear
echo "You haven't selected an appropriate option - try again"
fi
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.