LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 10-31-2016, 08:19 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Rep: Reputation: Disabled
Back with another stubborn BASH script


My idea was to write a script that removed JPEG comments that certain apps write in by default. I know the JPEG Comment header is minimal in terms of the overall file length of a JPEG, but over the years, strings like "CREATOR:GD-JPEG 1.0" or "Compupic" have annoyed me (not to mention the former showed up in bash 3.x in stdout on executing a FILE command). I backpedaled a bit with this script, focusing on the familiar "Created with GIMP" comment line, but the script gives me this error
Code:
line 16: syntax error near unexpected token `fi'
when I try to run it.

So here's the full script in its latest state (I commented out 'exiftool,' etc., since the shell wasn't getting that far in the first place):

Code:
#!/bin/bash

 while read line; do
	file0=$line
	comm1=$(exiftool -fast5 -Comment "$line")
	if [ -n "$comm1" ];
		echo "$file0 has Comment data."
		echo -e "$file0^$comm1" >>hascomment.txt
		if [[ $comm1 =  "Created with GIMP"  ]]; then
			echo -e "$file0 has a GIMP Comment. Writing to file."
			echo -e "$file0">>has-gimp-comment.txt
#			exiftool -fast5 -overwrite_original_in_place -q -Comment= $file0
			echo -e "Comment data removed from $file0."
			echo -e "$file0">>comment-cleared.txt
		fi
	fi
	
done< list.txt
I think I just need another pair of eyes to scope out the problem.

Carver

Last edited by L_Carver; 10-31-2016 at 08:24 AM.
 
Old 10-31-2016, 08:30 AM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,555

Rep: Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088
You are missing the "then" for your first "if".
 
1 members found this post helpful.
Old 10-31-2016, 09:34 AM   #3
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Current: Debian and OpenSUSE. Past: Arch, RedHat (pre-RHEL). FreeBSD & OpenBSD novice, Hackintosh
Posts: 1,193
Blog Entries: 7

Rep: Reputation: 336Reputation: 336Reputation: 336Reputation: 336
Quote:
Originally Posted by rknichols View Post
You are missing the "then" for your first "if".
This is why, although certainly not required, I tend to put 'then' on it's own line rather than combining it with the if clause. It's a lot easier to spot if it's missing.
 
1 members found this post helpful.
Old 11-01-2016, 12:41 AM   #4
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
I uncommented the "exiftool" line, but not the "$file0 has comment data" and the export to the text file. When I've run the script, the conditional
Code:
if [[ $comm1 =  "Created with GIMP"  ]]; then
doesn't return any "$file0 has GIMP comment" lines, and I can't puzzle out why not. Am I wrong to nest that "if then" in the other one?

Carver
 
Old 11-01-2016, 04:15 AM   #5
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Current: Debian and OpenSUSE. Past: Arch, RedHat (pre-RHEL). FreeBSD & OpenBSD novice, Hackintosh
Posts: 1,193
Blog Entries: 7

Rep: Reputation: 336Reputation: 336Reputation: 336Reputation: 336
Quote:
Originally Posted by L_Carver View Post
I uncommented the "exiftool" line, but not the "$file0 has comment data" and the export to the text file. When I've run the script, the conditional
Code:
if [[ $comm1 =  "Created with GIMP"  ]]; then
doesn't return any "$file0 has GIMP comment" lines, and I can't puzzle out why not. Am I wrong to nest that "if then" in the other one?

Carver
Try:

Code:
if [[ "$comm1" =  "Created with GIMP"  ]]; then
You must match quoting. You're running into a word splitting issue here.
 
Old 11-01-2016, 05:22 AM   #6
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
goumba,

Thanks, That did it.

Carver
 
Old 11-01-2016, 06:28 AM   #7
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Current: Debian and OpenSUSE. Past: Arch, RedHat (pre-RHEL). FreeBSD & OpenBSD novice, Hackintosh
Posts: 1,193
Blog Entries: 7

Rep: Reputation: 336Reputation: 336Reputation: 336Reputation: 336
You're welcome. If you forget anything else while scripting, remember quoting. Quoting. Shall I say it again?

BTW that applies to commands at a prompt, too.
 
  


Reply

Tags
bash, comment, error, loop


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
want to back up all of my cdr and dvdr. Bash script? Shay Linux - Software 1 07-22-2012 03:43 AM
Bash shell script: Str(007) to int(7),increment it(8) & convert back to string(008) drwatson_droid Programming 5 12-01-2011 10:44 AM
[SOLVED] how to run 2 bash command back-to-back in bourneShell nass Slackware 7 10-10-2011 05:23 PM
Passing PHP to bash script and then back. TXRob Programming 7 07-16-2010 09:37 AM
cd keeps snapping back to current directory when called from bash script ghrellin Linux - General 5 08-28-2005 12:50 PM

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

All times are GMT -5. The time now is 02:08 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
Open Source Consulting | Domain Registration