This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: stupid spaces in environment vars


David Bear wrote:
> I would like to have used something like
> 
> cd $USERPROFILE
> 
> in a bash script but since windows insists on putting spaces in
> names, this seems impossible.

You might be happier writing your scripts in zsh:

bash%  cd;pwd
/home/gsw
bash%  export SP="silly path"
bash%  mkdir "$SP"         # Note the quotes
bash%  cd $SP              # Oops, forgot to quote!
bash: cd: silly: No such file or directory
bash%  exec zsh            # Make it a one-way trip :-)
zsh%  cd $SP
zsh%  pwd                  # Hey, it worked!
/home/gsw/silly path

Or get used to always using quotes when you use a variable
that could possibly contain a space. Trying to pre-escape
environment strings for bash gets messy real quick.

Yes, I know the real problem usually comes when you try to
build command lines in environment variables. You need to
separate parameters without splitting paths. You can do
this in ZSH as well, either by forcing the old behavior as
needed (through expansion options and/or eval, along with
built-in support for basically what you're asking for) or
by using better array-based methods:

zsh%  cd;pwd
/home/gsw
zsh%  command="cd ${(q)SP}"  # try (qq)/(qqq)/(qqqq) also
zsh%  echo $command
cd silly\ path
zsh%  eval $command
zsh%  pwd
/home/gsw/silly path
zsh%  cd;pwd
/home/gsw
zsh%  command=(cd $SP)
zsh%  $command               # no eval needed
zsh%  pwd
/home/gsw/silly path

gsw

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]