ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi
I am learning Linux Shell Scripting from a book (titled: Mastering Shell Scripting, by: Andrew Mallett). On page 40, the author presented following example script (to evaluate students' grades):
Code:
#!/bin/bash
# Script to evaluate grades
# Usage: grade.sh student grade
# Author: @theurbanpenguin
# Date: 1/1/1971
if [ ! $# -eq2 ] ; then
echo "You must provide <student><grade>
exit 2
fi
case $2 in
[A-C]|[a-c]) echo "$1 is a star pupil"
;;
[Dd]) echo "$1 needs to try a little harder!"
;;
[E-F]|[e-f]) echo "$1 could do a lot better next year"
;;
*) echo "Grade could not be evaluated for $1"
esac
However, upon running the script by following command:
Code:
./grade.sh bob b
gives following error:
Code:
grade.sh: line 17: unexpected EOF while looking for matching `"'
grade.sh: line 19: syntax error: unexpected end of file
Can you guide me that whats wrong here with the code?
Thanks
Hi
I am learning Linux Shell Scripting from a book (titled: Mastering Shell Scripting, by: Andrew Mallett). On page 40, the author presented following example script (to evaluate students' grades):
Code:
#!/bin/bash
# Script to evaluate grades
# Usage: grade.sh student grade
# Author: @theurbanpenguin
# Date: 1/1/1971
if [ ! $# -eq2 ] ; then
echo "You must provide <student><grade>
exit 2
fi
case $2 in
[A-C]|[a-c]) echo "$1 is a star pupil"
;;
[Dd]) echo "$1 needs to try a little harder!"
;;
[E-F]|[e-f]) echo "$1 could do a lot better next year"
;;
*) echo "Grade could not be evaluated for $1"
esac
However, upon running the script by following command:
Code:
./grade.sh bob b
gives following error:
Code:
grade.sh: line 17: unexpected EOF while looking for matching `"'
grade.sh: line 19: syntax error: unexpected end of file
Can you guide me that whats wrong here with the code? Thanks
Sorry, but I find this fairly ironic that you're reading a book on how to write shell scripts that has explanations, examples, etc....and ask us to figure it out what's wrong.
That said, I'd suggest you look at the error message, think about what it means, and then look *CAREFULLY* at what you keyed in. The error tells you what you're missing; this is part of the learning process for programming, and it is very, VERY frustrating. It is also valuable later on, since it'll make things like this much easier to fix in the future.
Sorry, but I find this fairly ironic that you're reading a book on how to write shell scripts that has explanations, examples, etc....and ask us to figure it out what's wrong.
That said, I'd suggest you look at the error message, think about what it means, and then look *CAREFULLY* at what you keyed in. The error tells you what you're missing; this is part of the learning process for programming, and it is very, VERY frustrating. It is also valuable later on, since it'll make things like this much easier to fix in the future.
The error is fixed, thanks to pan64.
The script contains 18 lines but the error is saying "Line 19". Isn't that strange?
just try to understand the error messages you got:
Code:
grade.sh: line 17: unexpected EOF while looking for matching `"' -> there is an unpaired "
grade.sh: line 19: syntax error: unexpected end of file -> end of file and still not found the pair
by the way, if you want to say thanks jus click on yes
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800
Rep:
Quote:
Originally Posted by zetrotrack000
...
gives following error:
Code:
grade.sh: line 17: unexpected EOF while looking for matching `"'
grade.sh: line 19: syntax error: unexpected end of file
Can you guide me that whats wrong here with the code?
Thanks
Yes. When the shell gripes about not finding a quote, you should begin by looking at all the lines before the line number included in the error messge. What's happening is that the quote in "line 17" is being interpreted as the closing quote for a quote in a previous line. You've forgotten a quote somewhere above. Read your code carefully... I think it'll jump out at you.
I'd also look into using an editor that "understands" shell scripts and automagically indents your code (usually by pressing "Tab"). Vim might do this. Emacs (or one of its close relatives) certainly does this. Either will highlight variables and keywords in your script to help you distinguish between the two. You'll usually need to ensure that the editor knows what language it's dealing with. I do this by doing something like:
Once the editor sees the "shebang" line it knows to employ shell rules for highlighting and indentation. The same goes for other languages you might be using. Believe me, once you start using an editor like that... you'll never go back.
You mean the website that checked your code FOR YOU, rather than you learning/thinking about what was going on?
Quote:
The script contains 18 lines but the error is saying "Line 19". Isn't that strange?
No...it isn't, probably because you had a blank-line at the end of your script, or an unmatched pair somewhere. Again, referencing the book would teach you why this happens.
If you looked carefully at the error that clearly said you were missing one of (`"') those characters, and then looked carefully at line 7, you would have seen where you were missing one. Again...you would have learned to spot an error on your own, without a website telling you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.