* handling spaces in variables
@ 2007-04-27 1:07 Alexy Khrabrov
2007-04-27 3:33 ` Phil Pennock
0 siblings, 1 reply; 3+ messages in thread
From: Alexy Khrabrov @ 2007-04-27 1:07 UTC (permalink / raw)
To: zsh-users
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: handling spaces in variables
2007-04-27 1:07 handling spaces in variables Alexy Khrabrov
@ 2007-04-27 3:33 ` Phil Pennock
2007-04-27 6:22 ` Alexy Khrabrov
0 siblings, 1 reply; 3+ messages in thread
From: Phil Pennock @ 2007-04-27 3:33 UTC (permalink / raw)
To: zsh-users
On 2007-04-26 at 18:07 -0700, Alexy Khrabrov wrote:
> I'm running zsh on MacOSX,
That might be your user shell, but that doesn't mean /bin/sh is zsh.
Unfortunately, when I check, something is setting SHELL to the shell
from the user database. Bah!
> #!/bin/sh
Change that to #!/bin/zsh
After that, you'll have zsh behaviour. Which, by default, does *NOT*
split on whitespace the way that every other shell does. Making zsh
especially nice on MacOS.
-Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: handling spaces in variables
2007-04-27 3:33 ` Phil Pennock
@ 2007-04-27 6:22 ` Alexy Khrabrov
0 siblings, 0 replies; 3+ messages in thread
From: Alexy Khrabrov @ 2007-04-27 6:22 UTC (permalink / raw)
To: zsh-users
Phil -- fantastic, thanks a lot! BTW, I reformat all of my mac
drives, including the main one in my MacBook, as HFSX, case-sensitive,
journaled. That allows for nice zsh and generally Unix-like behavior.
Cheers,
Alexy
On 4/26/07, Phil Pennock <zsh-workers+phil.pennock@spodhuis.org> wrote:
> On 2007-04-26 at 18:07 -0700, Alexy Khrabrov wrote:
> > I'm running zsh on MacOSX,
>
> That might be your user shell, but that doesn't mean /bin/sh is zsh.
> Unfortunately, when I check, something is setting SHELL to the shell
> from the user database. Bah!
>
> > #!/bin/sh
>
> Change that to #!/bin/zsh
>
> After that, you'll have zsh behaviour. Which, by default, does *NOT*
> split on whitespace the way that every other shell does. Making zsh
> especially nice on MacOS.
>
> -Phil
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-04-27 6:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-27 1:07 handling spaces in variables Alexy Khrabrov
2007-04-27 3:33 ` Phil Pennock
2007-04-27 6:22 ` Alexy Khrabrov
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).