bash: correct quoting with find and exiv2?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash: correct quoting with find and exiv2?
# 1  
Old 07-31-2010
bash: correct quoting with find and exiv2?

Hi,
I need to embed a metatag to image files which contain qrcodes, i usually do this with
Code:
exiv -M "set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw image.tif`" image.tif

which works fine. However I need to do this recursivly for whole directory and subdiretory structures.

I use to handle such jobs with the find -exec command, which in this case would looks like this.
Code:
find . -name '*.tif' -exec sh -c 'exiv -M \"set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw "{}"`\" {}' \;

Unfortunately this doesn't work because exiv2 is complaining wrong arguments on option -M.
But trying a similar comand by inserting echo to debug the line
Code:
find . -name '*.tif' -exec sh -c 'echo \"set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw "{}"`\" {}' \;

the whole thing looks quite right to me.

Someone please give me a hint what's going wrong?
THX in advance
# 2  
Old 07-31-2010
I am unable to test it but this is what I would try:
Code:
find . -name '*.tif' -exec sh -c 'exiv -M "set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw {}` {}' \;

# 3  
Old 07-31-2010
Thanks for this tip,
in principle you're right, this "{}" could be replaced with {} so I tried:
Code:
find . -name '*.tif' -exec sh -c 'exiv2 -M "set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw {}`" {}' \;

but unfortunately exiv2 is still complaining "error parsing arguments of -M"
# 4  
Old 07-31-2010
Does zbarimg support qrcode?

The command man zbarimg doesn't mention it, nor does it's site, zbar.sf.net.

---------- Post updated at 12:24 PM ---------- Previous update was at 12:09 PM ----------

You could also make a separate script and call it from find.
That would make sense if this is something you do occasionally or often.
Maybe put this in ~/bin/tagimg.
I haven't executed this, but it looks right.
Code:
#!/bin/sh
if [ -f "$1" ]; then
    $TEXT="$(zbarimg -q -Sdisable -Sqrcode.enable --raw "$1")"
    exiv -M "set Exif.Image.DocumentName '$TEXT'" "$1"
else
    echo "File not found \"$1\"" >/dev/stderr
fi

(Note that '$TEXT' gets expanded properly because the single quotes are inside double quotes.)

Then the find command becomes
Code:
find . -name '*.tif' -exec ~/bin/tagimg {} \;

# 5  
Old 08-01-2010
Hi,
thx for your answer, I'd hoped to enable the 1-line-solution but it seems like this won't work, so I will try your idea with scripting.

Quote:
Originally Posted by KenJackson
Does zbarimg support qrcode?

The command man zbarimg doesn't mention it, nor does it's site, zbar.sf.net.
Yes, from version 0.10 on, zbarimg detects and parses qrcodes and it works very reliable and fast!

Kind regards
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot find correct syntax to make file name uppercase letters

I have a file name : var=UsrAccChgRpt I want to make them upper case. Tried: $var | tr Error: tr: Invalid combination of options and Strings. Usage: tr | -ds | -s | -ds | -s ] String1 String2 tr { -d | -s | -d | -s } String1 Could you please help. I am using AIX... (2 Replies)
Discussion started by: digioleg54
2 Replies

2. Shell Programming and Scripting

Help with Bash quoting

I am trying to write a BASH script that will prompt a user to enter a number of days, then calculate the date. My problem is the date command uses single or double quotes. For Example.. date -d "7 days" Here is an example of some same code I am trying to work through. echo "when do you... (4 Replies)
Discussion started by: javajockey
4 Replies

3. Shell Programming and Scripting

Tricky BASH quoting question

I have some data files that I can identify by a certain pattern in the names using find. Every one of those data files has an XML file associated with it (can be multiple data files per XML file). The XML file is always up one directory from the data file(s) in a folder calledRun##### -... (12 Replies)
Discussion started by: Michael Stora
12 Replies

4. Shell Programming and Scripting

Check my script and correct the find command if wrong

Hello All, Here I am trying to find all the directories whose name starts with EFS or HOTFIX like in below example and below is my code but I don’t know why this is not working correctly. drwxr-xr-x 3 qabuild denccefs 4096 Sep 23 21:36 EFS110929A_SOURCE/ -rwxrwxr-x 1 qabuild... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

5. UNIX for Dummies Questions & Answers

How do I find the correct environment variables for MPI?

Hello all. I've been trying to install NWCHEM in parallel on a new cluster, and have been able to get it to work on single processors by ignoring any MPI environment variables. This is, of course, pretty worthless. So I'm starting over and trying to get thing set up right for the MPI. The key... (6 Replies)
Discussion started by: EinsteinMcfly
6 Replies

6. Shell Programming and Scripting

Correct bash substitution

Hello! I'm writing a shell script using #!/bin/bash instead of #!/bin/sh because of the substitution: ${!variable}, which won't work with sh. My main problem is the following (just a summarized example, the script is much more complex): # sourced from a configuration file, we have a lot of... (6 Replies)
Discussion started by: teresaejunior
6 Replies

7. Shell Programming and Scripting

Quoting issue: Trouble with bash strings in script

I can do this on the command line: sqsh -S 192.168.x.x -o tmp -U user -P fakepass -D horizon -C "\ select second_id from borrower where btype like '%wsd%' " I can also just leave the SQL at the end intact on one line .... ... However, when I throw this in a script like: $SQSH -o... (4 Replies)
Discussion started by: Bubnoff
4 Replies

8. Solaris

correct usage of find's -prune option

I know one of the more seasoned veterans probably opened this thread looking for their chance to refer me to the site's search feature and let me tell you. I'VE LOOKED!!!! And I didn't find anything helpful... So, I've got a windows background and I'm fond of its search feature which comes... (6 Replies)
Discussion started by: ProGrammar
6 Replies

9. Shell Programming and Scripting

BASH quoting behavior

The block below isn't a surprise:$ ls file1 file2 file3 $ x=* $ echo $x file1 file2 file3 $ echo '$x' $x $ echo "$x" * $But I found this block a bit bewildering:$ echo $x' >' * $I'm wondering why substitution wasn't performed on the $x, since it was unquoted (as far as I can tell).... (5 Replies)
Discussion started by: na5m
5 Replies
Login or Register to Ask a Question