Ubuntu This forum is for the discussion of Ubuntu Linux. |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
|
09-29-2016, 06:58 AM
|
#1
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Rep:
|
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
|
|
|
09-29-2016, 08:01 AM
|
#3
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep:
|
My bad
I'll do so in future. It's only a courtesy, after all.
|
|
|
09-29-2016, 08:22 AM
|
#4
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep:
|
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...
|
|
|
09-29-2016, 08:37 AM
|
#5
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,733
|
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.
|
09-29-2016, 04:09 PM
|
#6
|
Member
Registered: May 2005
Location: Florida, USA
Distribution: Pop_OS, Xubuntu
Posts: 152
Rep:
|
You can also pass the debugging options to the script via the command line:
Code:
bash -xv SCRIPTNAME
|
|
|
09-30-2016, 01:39 AM
|
#7
|
LQ Addict
Registered: Dec 2013
Posts: 19,872
|
Quote:
Originally Posted by L_Carver
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.
|
|
|
09-30-2016, 02:13 AM
|
#8
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,733
|
Quote:
Originally Posted by ondoho
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)
|
|
|
10-03-2016, 12:01 AM
|
#9
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep:
|
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
|
|
|
10-03-2016, 01:07 AM
|
#10
|
LQ Addict
Registered: Dec 2013
Posts: 19,872
|
please share your solution, so others can benefit from this in the future.
Life is a two-way street.
|
|
|
10-03-2016, 06:40 AM
|
#11
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep:
|
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.
|
|
|
10-03-2016, 07:04 AM
|
#12
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,733
|
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.
|
10-03-2016, 09:30 AM
|
#13
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep:
|
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
|
|
|
11-04-2016, 05:08 AM
|
#14
|
Member
Registered: Sep 2016
Location: Webster MA USA
Posts: 243
Original Poster
Rep:
|
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
|
|
|
11-04-2016, 05:25 AM
|
#15
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,733
|
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:
|
|
|
All times are GMT -5. The time now is 09:15 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|