"Escape" dollar sign and/or single quotes

Started by Fulco, April 07, 2016, 09:39:45 AM

Previous topic - Next topic

Fulco

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

Phil Harvey

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/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Fulco

#2
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

Phil Harvey

Quote from: Fulco on April 07, 2016, 10:17:04 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:

> exiftool -echo 'here'"'"'s a test'
here's a test


This also works:

> 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/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Fulco

#4
Thank you!  It works. It is indeed bash.

- Fulco