Author Topic: Quoting problem with multiple keywords in a bash-script  (Read 2052 times)

Archive

  • Newbie
  • *
  • Posts: 0
Quoting problem with multiple keywords in a bash-script
« on: May 12, 2010, 08:54:03 AM »
[Originally posted by linuxuser on 2007-04-17 10:39:56-07]

Since there is something wrong with my last thread, I start a new one for the quoting question.

I didn't find out how to quote this correctly:

Code:
> exiftool -IPTC:Keywords="Phil's Exif" -IPTC:Keywords="Tool" test.jpg
    1 image files updated

> exiftool -G -H -IPTC:keywords test.jpg
[IPTC]          0x0019 Keywords                        : Phil's Exif, Tool

> CMD="-IPTC:Keywords=\"Phil's Exif\" -IPTC:Keywords=\"Tool\""

> echo $CMD
-IPTC:Keywords="Phil's Exif" -IPTC:Keywords="Tool"

> exiftool $CMD test.jpg
Error: Error opening file - Exif"
    1 image files updated
    1 files weren't updated due to errors

> exiftool -G -H -IPTC:keywords test.jpg
[IPTC]          0x0019 Keywords                        : "Phil's, "Tool"

> exiftool "$CMD" test.jpg
    1 image files updated

> exiftool -G -H -IPTC:keywords test.jpg
[IPTC]          0x0019 Keywords                        : "Phil's Exif" -IPTC:Keywords="Tool"

Archive

  • Newbie
  • *
  • Posts: 0
Re: Quoting problem with multiple keywords in a bash-script
« Reply #1 on: May 12, 2010, 08:54:03 AM »
[Originally posted by exiftool on 2007-04-17 11:49:31-07]

The quoting is entirely shell dependent but you haven't told me
what shell you are using.  From the commands it looks to me like
you are using a bash shell, so I will answer under that assumption.

I ran a few tests and it appears that bash does a single-pass parsing
of the command line.  So expressions like $CMD are substituted,
but expressions within them are not.  So quotes inside a variable like
$CMD are literal.  So if there are quotes needed around a space inside
an argument, they must be done outside the variable.  Unfortunately
this limits the variable to a single argument.

- Phil

Archive

  • Newbie
  • *
  • Posts: 0
Re: Quoting problem with multiple keywords in a bash-script
« Reply #2 on: May 12, 2010, 08:54:03 AM »
[Originally posted by linuxuser on 2007-04-17 12:30:55-07]

Yes, I use the bash. If I understand your answer right, it cannot be done with a bash-script. But maybe someone has an idea, when I post more details. I collect keywords from different places and put them together in a variable. Maybe it could help to write the tags in a textfile? It would be no problem to put the keywords in a row or every keyword in a line.

Archive

  • Newbie
  • *
  • Posts: 0
Re: Quoting problem with multiple keywords in a bash-script
« Reply #3 on: May 12, 2010, 08:54:03 AM »
[Originally posted by linuxuser on 2007-04-17 13:01:17-07]

Maybe it can be done in a loop with a bash script. I didn't find out how to add another tag to existing "list tags".

Archive

  • Newbie
  • *
  • Posts: 0
Re: Quoting problem with multiple keywords in a bash-script
« Reply #4 on: May 12, 2010, 08:54:03 AM »
[Originally posted by exiftool on 2007-04-17 13:07:19-07]

Use "+=" to add another tag to a list:

Code:
exiftool -keywords+=new test.jpg

- Phil

Archive

  • Newbie
  • *
  • Posts: 0
Re: Quoting problem with multiple keywords in a bash-script
« Reply #5 on: May 12, 2010, 08:54:03 AM »
[Originally posted by linuxuser on 2007-04-17 13:41:27-07]

Thanks Phil, I will try your example in a bash script. The loop is very time consuming, so I would like to ask for a feature, to import list-tags from a text-file, where each tag is e.g. listed in a row or delimited by whatever you want or any other solution which works with list-tags and a bash-script. As always, exiftool is great!

Archive

  • Newbie
  • *
  • Posts: 0
Re: Quoting problem with multiple keywords in a bash-script
« Reply #6 on: May 12, 2010, 08:54:03 AM »
[Originally posted by exiftool on 2007-04-17 15:12:10-07]

would the -@ option do it for you?:

Code:
exiftool -@ args.txt test.jpg

where "args.txt" is something like:

Code:
-keywords=Phil's Exif
 -keywords=Tool

- Phil

Archive

  • Newbie
  • *
  • Posts: 0
Re: Quoting problem with multiple keywords in a bash-script
« Reply #7 on: May 12, 2010, 08:54:03 AM »
[Originally posted by linuxuser on 2007-04-17 18:22:20-07]

Thanks Phil, this works fine.