LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-16-2011, 05:48 PM   #1
SilversleevesX
Member
 
Registered: May 2009
Posts: 181
Blog Entries: 9

Rep: Reputation: 15
Need another pair of eyes (BASH script throwing a "s-e-n-u-t" error)


"s-e-n-u-t"? syntax error near unexpected token.
(I wasn't sure it rated acronym status, but setting off the first letter of each word with hyphens seemed appropriate.)

Anyway, here's the script:
Code:
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
survey=$(echo ${PWD##*/})
:>$survey-captions.txt
pic=0
function gettext () {
echo -e "What list will I be using?"
read thelist
}

gettext
d=1
while read 'line';
do
	file=${line##*/}
	s=$(exiv2 -g Iptc.Application2.Caption -Pv $line)
	t=$(exiv2 -g Xmp.dc.description -Pv $line)
	v=$(exiv2 -g Exif.Image.ImageDescription -Pv $line)
	echo -ne "Extracting Caption data from JPEG file $file.\nItem #$d.\n"
	if [ -n "$s" ] && [ -z "$t" ] && [ -z "$v" ]; then
		z=$s
	fi
	if [ -z "$s" ] && [ -n "$t" ] && [ -z "$v" ]; then
		z=$t
	fi
	if [ -z "$s" ] && [ -z "$t" ] && [ -n "$v" ]; then
		z=$v
	fi
	if [ -n "$s" ] && [ -n "$t" ] && [ -z "$v" ]; then
		z=$t
	if [ -z "$s" ] && [ -n "$t" ] && [ -n "$v" ]; then
		z=$v
	fi
	echo -e "$line:$z">>$survey-captions.txt
	d=$[d+1]
done<$thelist
SAVEIFS=$IFS
And the particular "s-e-n-u-t" I get is
Quote:
line 37: syntax error near unexpected token `done'
line 37: `done<$thelist'
I don't see what could be keeping BASH from seeing the
Code:
while read 'line';
up in line 14. Maybe somebody else does?

And as a side question: is there any way I can cut down on the number of if/fi's I have in this script. I'm not too fluent with case loops, but those would seem to be appropriate here.

Thanks for looking at this OP.

BZT
 
Old 11-16-2011, 05:57 PM   #2
kinneyd
LQ Newbie
 
Registered: Oct 2011
Posts: 21

Rep: Reputation: Disabled
Looks like you're missing a "fi" on line 32. That should fix the syntax error.
 
Old 11-16-2011, 05:57 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
1. you've skipped a fi
Code:
	if [ -n "$s" ] && [ -n "$t" ] && [ -z "$v" ]; then
		z=$t
	if [ -z "$s" ] && [ -n "$t" ] && [ -n "$v" ]; then
Here's some good bash HOWTO links; consider using case ... esac or 'elif'
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

2. If you want to empty a file
Code:
>$survey-captions.txt
is sufficient ie drop the ':'

3. a good cmd to use for debugging is
Code:
set -xv
usually next after '#!/bin/bash'
 
Old 11-16-2011, 06:32 PM   #4
SilversleevesX
Member
 
Registered: May 2009
Posts: 181
Blog Entries: 9

Original Poster
Rep: Reputation: 15
Many thanks to both of you...

I thought all my "ifs" were paired with "fi's" but evidently not.

Thanks for the links to tips on case loops. I haven't had all that much luck with 'elif', though maybe I wasn't using it quite right, either. I'll read up on both asap.


BZT
 
Old 11-16-2011, 07:09 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,356

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
Try this page http://tldp.org/LDP/Bash-Beginners-G...ect_07_02.html.
Also recommend [[ ]] http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS
 
Old 11-16-2011, 07:30 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,492

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
I would also question the use of quotes around the read variable. Not sure if it causes any issues but there is no value to it.
 
Old 11-17-2011, 09:52 AM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
Some comments on your script, starting with a few unnecessary patterns:

Code:
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
survey=$(echo ${PWD##*/})
d=$[d+1]
1) You shouldn't generally need to save or restore IFS inside a script, unless you need to use the default value again in it. All environment settings inside the script only affect the script itself, and will be discarded on exit.

2) Bash has a special $'' quoting style (usually called ansi-c style quotes, see the QUOTING section of the man page) for inserting non-printing characters. You can use this instead of echo -e:

Code:
IFS=$'\n\b'
But why would you need to set IFS to backspace?

3) You don't need to echo a parameter expansion. Just set the new variable directly:

Code:
survey=${PWD##*/}
4) $[..] is a very old, outdated, and deprecated syntax. Do not use it. The modern version is $((..)). But there are also ways to do arithmetic operations without expansion, in particular the let keyword and bash's ((..)) arithmetic brackets. You can also increment a variable directly with var++ when in an arithmetic context.

Code:
let d++
(( d++ ))
http://mywiki.wooledge.org/ArithmeticExpression

5) Always remember to quote your variable expansions! Remember the links I gave you in your last thread?

6) You probably want to use a single if..elif...else statement, rather than a series of separate ifs.

7) Also consider using bash's new [[..]] test instead of [..]. It's safer and more powerful. You could combine all your tests into one command, for one thing.

Code:
if [[ -n "$s" && -z "$t" && -z "$v" ]]; then
		z=$s
elif [[ -z "$s" && -n "$t" && -z "$v" ]]; then
		z=$t
elif ...
http://mywiki.wooledge.org/BashFAQ/031

By the way, assuming I understand it correctly, I believe you can replace the whole thing with this:
Code:
z=${v:-${t:-$s}}
If v doesn't exist, then it uses t, if t doesn't exist, it uses s.

parameter substitution

Finally, I just posted a comment in that thread with some scripting suggestions. You may want to take a look at it.

Last edited by David the H.; 11-17-2011 at 10:02 AM. Reason: fixed minor errors
 
  


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: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Sendmail unable to start "throwing Error Messeges" sachin_shetty Linux - Server 9 04-08-2011 01:45 PM
Unexpected end-of-file error (bash script) - need another pair of eyes. SilversleevesX Linux - Newbie 10 02-05-2010 02:21 PM
Unexpected end-of-file error (bash script) - need another pair of eyes. SilversleevesX Linux - Newbie 7 02-05-2010 02:12 PM
kernel compilation:throwing error related with sound during "make bzImage" b0nd Linux - Newbie 1 08-19-2005 09:16 AM


All times are GMT -5. The time now is 10:04 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration