Script Errors (loop, menu, etc, not found)
I'm currently taking classes for scripting in Linux. I used Linux 7.3 in school, as I do at my house. I had no problems creating these scripts at school, but I am having difficulties getting them to work here, at home.
I have reason to believe I am missing some packages, but I do not know which packages will work. This is my script: _______________________________________________________________ # Chris Jepson # Phonebook # Address Book menu = ./menu.book # Location of file. loop = y while [ "$loop" = y ] do # Print menu to screen. clear tput cup 3 12; echo "My Menu" tput cup 4 12; echo "_______________" tput cup 5 12; echo "P - Print Menu" tput cup 6 12; echo "A - Access Menu" tput cup 7 12; echo "S - Save Menu" tput cup 8 12; echo "Q - Quit" tput cup 10 19; done read choice || continue # Read Input. case $choice in [Aa]) ./menu;; [Pp]) ./menu;; [Ss]) ./save;; [Qq]) exit;; *) tput cup 14 4; echo "Invalid Code"; # Incorrect Input read choice;; # Input Entered esac done _______________________________________________________________ Each and every time I run my script file, it privides me the following error: _______________________________________________________________ ./menu.book: menu: command not found ./menu.book: loop: command not found _______________________________________________________________ Again, I believe I might be missing the package needed to run these script related programing commands, but I do not know which ones. If this is not a package problem, any help would be most desired. <smiles> Thanks in advance. |
1) Which shell are you trying to program in? There is not just one shell for Unix -- it could be Bourne shell, Korn shell, ash, bash, dash, zsh, csh, tcsh, etc.
2) Always put the magic line at the beginning of the file with the path to the shell with which you wish to run it, eg #! /bin/sh 3) As your lines look very much like Bourne shell, then you need to be aware that variable assignment syntax is VARIABLE="string" or VARIABLE=123 for integer. Note that there are no spaces around the equality sign. For further information on programming in the Bourne shell man sh and for bash man bash Please note that when debugging your script you can put the line set -x to see executed staetments and set -v to see every interpreted line. These settings are turned off with set +x and set +v respectively. |
Corin, you rock! That fixed it.
I found a new flaw, but I was able to fix it. I had 2 done statements in there. Script now looks like the following: # Chris Jepson # Phonebook # Address Book #! /bin/sh menu=./menu.book # Location of file. loop=y while [ "$loop"=y ] do # Print menu to screen. clear tput cup 3 12; echo "My Menu" tput cup 4 12; echo "_______________" tput cup 5 12; echo "P - Print Menu" tput cup 6 12; echo "A - Access Menu" tput cup 7 12; echo "S - Save Menu" tput cup 8 12; echo "Q - Quit" tput cup 10 19; read choice || continue # Read Input. case $choice in [Aa]) ./menu;; [Pp]) ./menu;; [Ss]) ./save;; [Qq]) exit;; *)tput cup 14 4; echo "Invalid Code"; # Incorrect Input read choice;; # Input Entered esac done ____________________________________________________________ The out put is the following: My Menu _______________ P - Print Menu A - Access Menu S - Save Menu Q - Quit ____________________________________________________________ Again, thanks alot. <smiles> |
You are most welcome.
I have made the same mistake myself once or twice with inadvertently introducing a space by the = sign. BTW # Chris Jepson # Phonebook # Address Book #! /bin/sh You must put the #! /bin/sh as the very FIRST line of the script, no exceptions. Once you do that, and chmod 700 script_name, you can just do ./script_name and it will be executed with the correct shell regardless of which shell you are currently in. Just to see the diference, try the command $ file script_name before and after you make the correction, and you will see the magic at work. |
Quote:
|
/bin/bash, that is a contridiction. The first reply to my thread was how to resolve the problem. The second one was how to reinforce stronger scripting writing. Both of which were very helpful. The post placed prior to yours are clear indicators that people did understand my request.
BTW /bin/bash, to answer your question regarding IBM and Sco, Sco is Unix, not Linux. |
Actually the problem is the uncertainty in this statement
Quote:
A) you created the scripts at school and then you tried what you had created at school on your system at home, they did not work on your home system or B) you created the scripts at school and then when you {re-}created them at home and tried to run them, what you had {re-}created at home did not work ????? Most people reading what you had written would assume the first meaning. |
Correct. Option A) was my desired question. As followed, I was commenting a concern about missing packages.
I asumed there was a possablity weather or not the script was not working because a statement in the script required a dependant package not installed in my system. Obviously, I asumed wrong. I am still new with Linux, I'm allowed to be dumb... for now. <laughs> However, the confusion between coping and recreate the script file is concerning to me. I'll be sure to be a bit more discriptive next time. Thanks again. |
All times are GMT -5. The time now is 03:53 AM. |