Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

handling spaces in variables



I'm running zsh on MacOSX, and Mac generously sprinkles spaces in
system paths.  Thus I had to painfully quote all cases where a
parameter or a variable is passed to system commands.  I wonder
whether there's a way to minimize such quoting.  Here's an example.
Some Leica cameras write a RAW file along with a JPG.  The below
script takes a directory path as a parameter and creates a
subdirectory with the trailing name in a fixed central JPG Archive.
Then it moves all JPG files from the original directory to the newly
created one.  The script ended up as follows:

#!/bin/sh
SRC=`basename "$1"`
JPGROOT='/Volumes/Mir/JPG Archive/Leica'
TGT="$JPGROOT/$SRC"
mkdir "$TGT"
mv "$1"/*.JPG "$TGT"

Basically, I have to quote a potentially space-containing variable
anywhere on the right-hand side, and when passing back so system
commands.

Can I somehow declare e.g. TGT a self-escaping variable and avoid
quoting it all the time?  I.e., whever I now write "$TGT" on the RHS,
I'd write just $TGT, and zsh would supply the quotes?

Cheers,
Alexy



Messages sorted by: Reverse Date, Date, Thread, Author