LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Script Errors (loop, menu, etc, not found) (https://www.linuxquestions.org/questions/linux-software-2/script-errors-loop-menu-etc-not-found-78601/)

dolvmin 08-03-2003 01:14 PM

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.

Corin 08-03-2003 01:48 PM

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.

dolvmin 08-03-2003 02:10 PM

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>

Corin 08-03-2003 02:39 PM

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.

/bin/bash 08-11-2003 05:15 AM

Quote:

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.
See that statement at the beginning would lead everyone away from checking syntax. I thought you brought the script home on a floppy and it didn't work on your home computer, but did work on your school computer. You should keep an updated copy handy on disk. Or email it to a web account you can access from home or school.

dolvmin 08-11-2003 07:01 PM

/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.

Corin 08-12-2003 07:36 PM

Actually the problem is the uncertainty in this statement

Quote:

I had no problems creating these scripts at school, but I am having difficulties getting them to work here, at home.
Does this mean that

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.

dolvmin 08-14-2003 12:50 AM

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.