LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 09-29-2016, 06:58 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
Unhappy What's wrong with this bash script


This ran fine in Ubuntu 11.04. It uses exiftool to add captions/XMP descriptions to image files with metadata containers, mainly and mostly JPEGs.

Code:
#!/bin/bash -i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

function gettext () {
echo -e "What text will I be using?"
read -e item
#Allowing for, and correcting, the trailing space in interactive mode
if [[ "$item" =~ " " ]]; then
	capfile=${item% *}
else
	capfile=$item
fi
#echo $capfile
}
gettext
while IFS=^ read file cap
do
exiftool -fast5 -overwrite_original_in_place -q -Caption-Abstract="$cap" -XMP-xmp:Description="$cap" $file
echo -e "Captions applied to $file"

done<$item

IFS=$SAVEIFS
The error I keep getting has to do with the shell seeing the caption text as a file it can't find.

My bash version is 4.3.30. I'm using Trinity R14.03 on a Q4OS (can't recall the specific version #), in case any of that matters.

Llewellyn
 
Old 09-29-2016, 07:07 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,733

Rep: Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556
Next time please post the real error message.
https://bash.cyberciti.biz/guide/Here_strings
 
Old 09-29-2016, 08:01 AM   #3
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
My bad

I'll do so in future. It's only a courtesy, after all.
 
Old 09-29-2016, 08:22 AM   #4
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Here are the errors:

Code:
File not found: Caption-Abstract=Her name is Marie. A month ago, she had a pregnancy...
File not found: XMP-xmp:Description=Her name is Marie. A month ago, she had a pregnancy...
 
Old 09-29-2016, 08:37 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,733

Rep: Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556
insert set -xv at the beginning of your script, that will help you to understand what's happening. Especially check the variables file and cap.
Why did you use IFS=^ ?
 
1 members found this post helpful.
Old 09-29-2016, 04:09 PM   #6
Dave Lerner
Member
 
Registered: May 2005
Location: Florida, USA
Distribution: Pop_OS, Xubuntu
Posts: 152

Rep: Reputation: 44
You can also pass the debugging options to the script via the command line:

Code:
bash -xv SCRIPTNAME
 
Old 09-30-2016, 01:39 AM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by L_Carver View Post
It's only a courtesy, after all.
no it's not.
it's the most important info to provide.
it is your system trying to talk to you.

anyhow, maybe exiftool's command line options have changed with a new version?
that's my first idea, really off the top of my head.
 
Old 09-30-2016, 02:13 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,733

Rep: Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556
Quote:
Originally Posted by ondoho View Post
it's the most important info to provide.
it is your system trying to talk to you.
Do you know the message you posted means: something is completely wrong with that exiftool command. I mean the parameters/arguments are not really understood or handled properly.
That cannot be seen in your original post.
set -xv will print a lot of debugging information and you will see the variables, commands as they used by the shell. And that may help you to understand what's happening. Or you can try to post the output and we will try to give you a solution (or just go forward one step)
 
Old 10-03-2016, 12:01 AM   #9
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Whichever one of you suggested i re-think the variables (file and cap), I changed them and the script worked as it did when I used Ubuntu. Thanks for the help.
Carver
 
Old 10-03-2016, 01:07 AM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
please share your solution, so others can benefit from this in the future.
Life is a two-way street.
 
Old 10-03-2016, 06:40 AM   #11
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
The revised, probably slightly extended, script code looks like this:

Code:
#!/bin/bash -i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
set -xv
function gettext () {
echo -e "What text will I be using?"
read -e item
#Allowing for, and correcting, the trailing space in interactive mode
if [[ "$item" =~ " " ]]; then
	capfile=${item% *}
else
	capfile=$item
fi
#echo $capfile
}
gettext
while IFS=^ read file1 caption
do
exiftool -fast5 -overwrite_original_in_place -q Caption-Abstract="$caption" XMP-xmp:Description="$caption" $file1
echo -e "Captions applied to $file1"

done<$item

IFS=$SAVEIFS
You'll notice "file" is now "file1" and "cap" is now "caption." That little difference was enough to make it work. I guess it's because 'file' and 'cap' are reserved words (in fact one is a command) in bash; I'd forgotten asmuch.

Carver

Last edited by L_Carver; 10-03-2016 at 06:46 AM.
 
Old 10-03-2016, 07:04 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,733

Rep: Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556
Code:
if [[ "$item" =~ " " ]]; then
	capfile=${item% *}
else
	capfile=$item
fi
capfile is not used anywhere, so this part is useless
still don't know what is IFS=^ good for.
IFS=$(echo -en "\n\b") was copied from here: http://unix.stackexchange.com/questi...bash-scripting (or a similar page) and again I do not really understand. IFS=$'\n' would be probably better.
 
1 members found this post helpful.
Old 10-03-2016, 09:30 AM   #13
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
You're right. I've been told the "IFS=$(echo -en "\n\b")" was too much w/re other scripts I've written. It worked in Cygwin (in fact it worked BEST in Cygwin when anything less didn't [ymmv]), so it's a habit of mine. BASH 4 doesn't seem to need it -- in Linuxes I've used, at any rate -- so I'll try to break the habit going forward.

Carver
 
Old 11-04-2016, 05:08 AM   #14
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Thumbs down ondoho your attention please

In another thread (since closed) you asked:

Quote:
Originally Posted by ondoho

2) what's all this messing about with IFS?

5) what 'while IFS=^ ' supposed to mean?
I just added the SAVEIFS & IFS= lines to a script that kept returning "File not found" errors on files with spaces in their names. So bash 4 handles that without specifying file separators, does it? It has yet to do so for me.

Carver
 
Old 11-04-2016, 05:25 AM   #15
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,733

Rep: Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556Reputation: 7556
this thread is continued here: http://www.linuxquestions.org/questi...in-4175592861/
The script posted in this thread is now modified, IFS was removed....
please do not run several threads discussing the same script (and posting/using different versions of it).
by the way the actual state is still not ok,
Code:
 echo "Uses exiftool."
 while read line; do
	file0=$line
here " should be used if you have problems with spaces:
Code:
 file0="$line"
 
  


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
[SOLVED] What is wrong with my bash script? HalfEmptyHero Programming 2 08-02-2011 04:03 PM
What am I doing wrong in this bash script ? bashprog Programming 4 10-10-2010 07:19 PM
What Is Wrong With This Bash Script File? George2 Programming 24 05-11-2006 08:29 PM
My first BASH script, what's wrong with it? szf2 Linux - Newbie 2 11-12-2003 01:43 PM
Basic BASH script, what's wrong??? Satriani Linux - General 2 06-02-2003 05:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 09:15 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