UNIX shell script problem

Place to talk about all that new hardware and decaying software you have.

Moderator: General Mods

Post Reply
Annihilated
Rookie
Posts: 47
Joined: Thu Aug 26, 2004 4:50 am
Location: Georgia
Contact:

UNIX shell script problem

Post by Annihilated »

I'm writing a shell script (or a series of them) for a project, and I'm getting this error.

Code: Select all

./proj1.sh: line 18: syntax error near unexpected token `)'
./proj1.sh: line 18: `[Ee])'
This is what my file looks like. It's supposed to be some kind of a menu where you enter a character to open another file.

Code: Select all

#!/bin/sh
#Project 1 CSC 3320

stop=0
while
test $stop -eq 0
do
cat << ENDOFMENU
Main Menu (e) Edit Submenu (r) Report Submenu (q) Quit
ENDOFMENU
echo -n 'Please enter a letter: '
read reply
echo case $reply in
[Ee])
echo "Edit Submenu:"
./edit.sh
;;
[Rr])
echo "Report Submenu:"
./report.sh
;;
[Qq])
stop=1
;;
*)
echo Illegal choice
;;
esac
done
I'm not really sure I know what I'm doing, but I did get the "case in" to work in a different file, so maybe it's a problem with my "while" loop?
funkyass
"God"
Posts: 1128
Joined: Tue Jul 27, 2004 11:24 pm

Post by funkyass »

Might I suggest using perl instead?

drop the square brackets, go with ( R | r)
Does [Kevin] Smith masturbate with steel wool too?

- Yes, but don’t change the subject.
Annihilated
Rookie
Posts: 47
Joined: Thu Aug 26, 2004 4:50 am
Location: Georgia
Contact:

Post by Annihilated »

Well we haven't been taught Perl yet, so I don't really know it. Plus this is a project based on UNIX shell scripting, so we have to do it that way. And trying without the square brackets didn't change the error. For example I used to have it as just "e"). It just doesn't like that ')' character for some reason.
Killa B
♥ Love Freak FlonneZilla ♥
Posts: 111
Joined: Sun Apr 01, 2007 12:59 am
Location: USA
Contact:

Re: UNIX shell script problem

Post by Killa B »

Code: Select all

echo case $reply in
Should just be

Code: Select all

case $reply in

Also, I don't know about you, but my computer really doesn't like

Code: Select all

cat << ENDOFMENU 
Main Menu (e) Edit Submenu (r) Report Submenu (q) Quit 
ENDOFMENU
It works if I change it to

Code: Select all

echo "Main Menu (e) Edit Submenu (r) Report Submenu (q) Quit"

P.S. You should try indenting once in a while. :shock:
User Error: Please replace user
tukuyomi
Rookie
Posts: 39
Joined: Mon Aug 02, 2004 5:14 am
Contact:

Post by tukuyomi »

Which Unix/shell version are you using?
It works on my system if I remove the echo from the case.. command
A bit of rewrite would give you this, btw

Code: Select all

#!/bin/sh
#Project 1 CSC 3320

stop=0
while [ $stop -eq 0 ]; do
	cat << ENDOFMENU
Main Menu (e) Edit Submenu (r) Report Submenu (q) Quit
ENDOFMENU
	read -p'Please enter a letter: ' reply
	case $reply in
	e|E)
		echo "Edit Submenu:"
		./edit.sh
		;;
	r|R)
		echo "Report Submenu:"
		./report.sh
		;;
	q|Q)
		stop=1
		;;
	*)
		echo 'Illegal choice'
		;;
	esac
done
Annihilated
Rookie
Posts: 47
Joined: Thu Aug 26, 2004 4:50 am
Location: Georgia
Contact:

Post by Annihilated »

Sorry about the lack of indenting in my code, I actually just pulled it from an example file and modified it to try to fit what I wanted to do. The file wasn't formatted so I had to enter line breaks and figure out where they began. So I wasn't totally sure on how the code was supposed to be structured.

Anyway I've been trying to make changes to my file in vi (that's all we get on this server), but it's giving me one of those "E514: write error (file system full?)" things when I try to save. I am using UNIX via SSH Secure Shell Client, and the shell I'm using is Bash. I emailed the instructor about this error already, I'm not sure if it's anything I can do.

Thanks for all the help so far.
Post Reply