Author Topic: "Escape" dollar sign and/or single quotes  (Read 1946 times)

Fulco

  • Full Member
  • ***
  • Posts: 74
"Escape" dollar sign and/or single quotes
« on: April 07, 2016, 09:39:45 AM »
With the -p option I print command lines which I can apply to other files. For example:

exiftool -q -q -m -n -if 'not $GPSLatitude =~/-/i and not $GPSLongitude =~/-/i' -p 'exiftool -GPSLatitude="$GPSLatitude" -GPSLatitudeRef="North" -GPSLongitude="$GPSLongitude" -GPSLongitudeRef="East" -overwrite_original -P ' -execute -q -q -m -n -if '$GPSLatitude =~/-/i  and not $GPSLongitude =~/-/i' -p 'exiftool -GPSLatitude="$GPSLatitude" -GPSLatitudeRef="South" -GPSLongitude="$GPSLongitude" -GPSLongitudeRef="East" -overwrite_original -P ' -execute -q -q -m -n -if 'not $GPSLatitude =~/-/i and $GPSLongitude =~/-/i' -p 'exiftool -GPSLatitude="$GPSLatitude" -GPSLatitudeRef="North" -GPSLongitude="$GPSLongitude" -GPSLongitudeRef="West" -overwrite_original -P ' -execute -q -q -m -n -if '$GPSLatitude =~/-/i and $GPSLongitude =~/-/i' -p 'exiftool -GPSLatitude="$GPSLatitude" -GPSLatitudeRef="South" -GPSLongitude="$GPSLongitude" -GPSLongitudeRef="West" -overwrite_original -P ' -common_args

What I also want to do is to print a command which contain dollar signs and/or single quotes. Is that possible?

- Fulco
« Last Edit: April 07, 2016, 10:35:56 AM by Fulco »

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14759
    • ExifTool Home Page
Re: "Escape" dollar sign and/or single quotes
« Reply #1 on: April 07, 2016, 09:58:02 AM »
Hi Fulco,

In the exiftool -p argument, "$$" may be used to print "$".

How to generate a single quote inside single quotes depends on what shell you are using.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Fulco

  • Full Member
  • ***
  • Posts: 74
Re: "Escape" dollar sign and/or single quotes
« Reply #2 on: April 07, 2016, 10:17:04 AM »
Hello Phil,

I use the Terminal app on my Mac if that is what you mean. I've already tried a back slash but it didn't work.

- Fulco
« Last Edit: April 07, 2016, 02:29:20 PM by Fulco »

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14759
    • ExifTool Home Page
Re: "Escape" dollar sign and/or single quotes
« Reply #3 on: April 07, 2016, 10:32:07 AM »
I use the Terminal app on my Mac if that is what you mean.

No, I mean the shell running the terminal.  I use tcsh, but I think bash is default for recent versions of OS X.

I don't know if this is the best way, but this works in bash to get a single quote:

Code: [Select]
> exiftool -echo 'here'"'"'s a test'
here's a test

This also works:

Code: [Select]
> exiftool -echo 'here'\''s a test'
here's a test

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Fulco

  • Full Member
  • ***
  • Posts: 74
Re: "Escape" dollar sign and/or single quotes
« Reply #4 on: April 07, 2016, 10:39:25 AM »
Thank you!  It works. It is indeed bash.

- Fulco
« Last Edit: April 07, 2016, 02:29:34 PM by Fulco »