LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-03-2003, 01:14 PM   #1
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Rep: Reputation: 30
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.
 
Old 08-03-2003, 01:48 PM   #2
Corin
Member
 
Registered: Jul 2003
Location: Jette, Brussels Hoofstedelijk Gewest
Distribution: Debian sid, RedHat 9, Suse 8.2
Posts: 446

Rep: Reputation: 31
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.
 
Old 08-03-2003, 02:10 PM   #3
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
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>
 
Old 08-03-2003, 02:39 PM   #4
Corin
Member
 
Registered: Jul 2003
Location: Jette, Brussels Hoofstedelijk Gewest
Distribution: Debian sid, RedHat 9, Suse 8.2
Posts: 446

Rep: Reputation: 31
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.
 
Old 08-11-2003, 05:15 AM   #5
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
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.
 
Old 08-11-2003, 07:01 PM   #6
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
/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.
 
Old 08-12-2003, 07:36 PM   #7
Corin
Member
 
Registered: Jul 2003
Location: Jette, Brussels Hoofstedelijk Gewest
Distribution: Debian sid, RedHat 9, Suse 8.2
Posts: 446

Rep: Reputation: 31
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.
 
Old 08-14-2003, 12:50 AM   #8
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script loop bong.mau Programming 6 09-14-2005 07:38 PM
Bash Script and Loop error handling Kedelfor Programming 5 05-22-2005 02:22 PM
bash script for loop drisay Programming 5 12-25-2004 12:32 AM
bash script - for loop question rignes Programming 3 10-05-2004 11:16 PM
Loop in this perl script is not working meluser Programming 2 04-01-2003 08:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration