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-30-2018, 11:05 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 229

Rep: Reputation: Disabled
Question Anyone here ever scripted the exiv2 executable (in BASH)?


I've been trying to move a script that adds keywords from Exiftool (which seems to be getting slower -- natch; it's written in Perl) to Exiv2, 20+ times faster as it's written in 'good' (just ask the author) C++. But the issues I'm having are the following:
  • Breaking the string along comma delimiters, then reading the 'pieces' of that array in a loop.
  • Result 1: No keywords get written to the JPEG.
  • Result 2: One odd single keyword gets written to the JPEG.
Here's the script in its current iteration:
Code:
#!/bin/bash 

tuna=0; catfood=0
function dav () {
echo -e "What text file will I be using?"
read -er item
f=$item
while IFS="^" read -r f k
do
echo -e "File is \e[31m$f\e[0m"
if [[ ! -f "$f" ]]; then
	echo "I don't see $f in this directory."
	echo "Moving to next list item."
	continue
fi
((catfood++))
dothedeed
done<"$f"
}
function twokey () {
	taxt=$(echo "$k" | cut -d, -f2)
	keycount=$(echo "$k" | tr ',' ' ' | wc -w)
for keys in $(echo "$k" | tr ',' ' ' | wc -w)
do
echo "${keys}"
/usr/bin/exiv2 --keep -M"add Iptc.Application2.Keywords $taxt" -M"add Xmp.dc.subject $taxt" "$f"
((taxt++))
done
/usr/bin/exiv2 -g Iptc.Application2.Keywords -Pv "$f"
}
function dothedeed () {
echo -e "Adding Keywords to \e[5;42m$f\e[0m."
echo -e "$f\t$k"
keycount=$(echo "$k" | tr ',' ' ' | wc -w)
echo "$f: There are $keycount keywords."
echo "Here's the Keyword string."
echo -e "$k"
#	exiftool -sep "," -fast5 -overwrite_original_in_place -q -P -Keywords+="$k" -Subject+="$k" "$f"
twokey
((tuna++))
}

echo "Uses Exiftool."
echo

dav
echo "$tuna out of $catfood files were annotated with Keywords this time."

#putk
#echo "Here's the Keyword string."
#echo -e "$k"
Hope there's someone with experience in this area who can help me.

and to answer the question before it's asked: I have tried several times to "restore" (I was on it years ago) my credentials on Exvi2 Forum. I have even corresponded via email with Andreas Huggel, to no avail as of this date (30102018).

Carver

Last edited by L_Carver; 10-30-2018 at 11:08 AM. Reason: Un-commented one line in the code
 
Old 10-30-2018, 11:26 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,576

Rep: Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341
as far as I remember I suggested you to use shellcheck to check your script. Actually there is a serious issue, which might cause your problem. But first I would like to tell you I have no idea what is it all about. But I know it is not related to exiv2 at all, but the shell script itself. If you wish to see how it works please insert set -xv at the beginning and you will see how your lines are evaluated/understood by bash and also how are they really executed (which was told already too).
But return back to the error (what shellcheck found):
Code:
Line 11:
if [[ ! -f "$f" ]]; then
           ^-- SC2094: Make sure not to read and write the same file in the same pipeline.
 
Line 18:
done<"$f"
     ^-- SC2094: Make sure not to read and write the same file in the same pipeline.
This is the function:
Code:
 4 function dav () {
 5 echo -e "What text file will I be using?"
 6 read -er item
 7 f=$item
 8 while IFS="^" read -r f k
 9 do
10 echo -e "File is \e[31m$f\e[0m"
11 if [[ ! -f "$f" ]]; then
12 	echo "I don't see $f in this directory."
13	echo "Moving to next list item."
14	continue
15 fi
16 ((catfood++))
17 dothedeed
18 done<"$f"
19 }
You specified $f as filename and tried to read that, but in line 8 (not detected by shellcheck) $f is overwritten.
Later you use $f but I have no idea if it was the right value or not... (you could easily check it with set -xv)

Last edited by pan64; 10-30-2018 at 11:27 AM.
 
Old 10-30-2018, 11:56 AM   #3
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 229

Original Poster
Rep: Reputation: Disabled
Sorry, I forgot to mention that I ran shellcheck (both local and online), and it gives
Code:
SC2094: Make sure not to read and write the same file in the same pipeline.
for an error. The gitHhub page does refer to "read and write the same," but what I fail to understand is: that's what the script is supposed to do. Creating a dummy file in this instance is useless. Of course, there is the sidecar option (file extension .exv, which is really just a headerless JPEG), which the script could write and write back to the JPEG later on in the code.

I will give set -xv a shot and see what it shows.

Carver
 
Old 10-30-2018, 12:01 PM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,576

Rep: Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341Reputation: 4341
you still don't understand. You use the same variable $f for two different purposes. I'm really sure it is not what the script supposed to do.
(actually the shellcheck message is a bit misleading, it recognized there is something wrong, but the info is not really correct. Probably I will report it to the team).
 
Old 10-30-2018, 12:52 PM   #5
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 229

Original Poster
Rep: Reputation: Disabled
The line of code, as I understand it
Code:
while IFS="^" read -r f k
looks for the file and the string of keywords.
The line
Code:
/usr/bin/exiv2 --keep -M"add Iptc.Application2.Keywords $taxt" -M"add Xmp.dc.subject $taxt" "$f"
is supposed to write a word found between the commas (as set by line 21, taxt=$(echo "$k" | cut -d, -f2), and the for loop gives the next value of taxt, doesn't it? Or should the 'cut -d, -f2' be written differently?
I'm thinking the whole routine, maybe the whole script, makes use of a "false array" and that's why I still get odd bits of the string written as one and only one keyword. Example: the second word, blonde, in the test file I'm using was the only one written to the JPEG the last time I ran the script (using set -xv).

Carver
PS: Please do report the misinformation to shellcheck/github. I would appreciate it.
 
Old 11-15-2018, 04:52 AM   #6
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 229

Original Poster
Rep: Reputation: Disabled
Again, I think the problem is in that second line in function twokey, line 5 of the whole script. It keeps "picking" the first string after the first comma. I remember my original script (from years ago, not the one I posted here) had an echo showing which keyword was being added to foo.jpg. I added that echo and with a test file it echo'd one word (blonde, in this case).

Now I'm thinking of reverting to a bash 3 or earlier bash 4 method: invoking the comma as a second IFS, for the string of keywords. I just need a nudge in the right direction.

Carver
 
Old 11-16-2018, 02:06 PM   #7
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 229

Original Poster
Rep: Reputation: Disabled
Solved elsewhere, with the help of one of the maintainers of exiv2.

Thanks all the same.

Carver
 
Old 11-16-2018, 04:22 PM   #8
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.7.1908
Posts: 4,358

Rep: Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523Reputation: 1523
Quote:
Originally Posted by L_Carver View Post
Solved elsewhere, with the help of one of the maintainers of exiv2.

Thanks all the same.

Carver
Please share the solution here to help the next person with the problem.
Thank you.
 
  


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
Exiv2 Crashes when trying to open certain jpg images walecha Slackware 3 12-24-2012 02:14 AM
[SOLVED] Understanding Bash and Executable 'name' Ztcoracat Linux - General 19 11-24-2012 04:45 PM
A tip regarding Exiv2 on the command line SilversleevesX Linux - General 0 09-12-2012 07:37 AM
bash can't find executable which exists. krafczyk Linux - Software 5 08-09-2012 01:21 AM
BASH text executable blackbox Linux - Newbie 1 02-28-2005 07:49 AM

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

All times are GMT -5. The time now is 12:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration