Shell Scripting Question
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 Any help/advice is appreciated Regards Andrew |
instead of the if[${vvar}...]
maybe a switch would do... Code:
switch ${vvar} or even a while loop might be better ..check the syntax on that as well .. and i believe that the blinking cursor is dependant on your / the user's system and what not ...what terminal..etc...not sure that you can force that |
Code:
while [ 1 ] |
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 |
Code:
if [ ${vvar} == 1 ];then |
I also posted this in your other post in General Linux forum.
Code:
#!/bin/bash |
what is wrong is you forgot a semi colon
if [ ] ; <<<<< that one is missing on the last if statement. |
Thank you all especially you paonethestar
Thats exectly what i needed script writing can be a beautiful thing if you know what your doing 8^). |
/bin/bash what puts the #? at the bottom of the selections??
|
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. |
One last question
Currently list is shown like this 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 Regards Jester |
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 |
Instead u can use "echo -n " to remove trailing newlines.
Bye. |
(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 |
All times are GMT -5. The time now is 09:25 PM. |