Afficher un message
Vieux 21/08/2006, 19h50   #5
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: quoting pathnames with spaces

On Sun, 20 Aug 2006 20:38:28 -0500, Charles Russell wrote:
> Is there some way to define macro WPATH so that I can just type cp file
> $WPATH and not have to type the quotes, cp file "$WPATH", every time?
> (I'm using cygwin and have to contend with Windows pathnames.) If
> possible, the same macro should be usable in Bourne shell scripts as
> well as at the command line.


Use zsh, then you don't need the quotes (except for the case
where $WPATH may be empty in which case zsh does expand it to no
argument instead of an empty argument).

And if you want either of the other behaviors other shell have
by default upon variable expansion, use:

cmd $=var

To ask that word splitting be performed upon the expansion

cmd $~var

to ask for filename genration (wildcards in $var to be
expanded).

cmd $=~var

combines both and is equivalent to

cmd $var

in other shells.

In other shells, you can do

IFS=
set -f

And you can then use variable expansion as in zsh. But note that
then command substitutions are not word split either and there's
no $=var nor $~var in other shells.

In any case, in zsh and with other shells with IFS=;set -f, in
scripts, it's still better to quote variable expansion (for the
expansion of empty variables to start with).

--
Stephane
  Réponse avec citation
 
Page generated in 0,04553 seconds with 9 queries