[SOLVED] Anyone here ever scripted the exiv2 executable (in BASH)?
Linux - SoftwareThis 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
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.
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.
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 10:08 AM.
Reason: Un-commented one line in the code
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)
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.
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).
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.