[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: quoting paths in environment variables could be improved

From: Paul Jarc
Subject: Re: quoting paths in environment variables could be improved
Date: Sat, 03 Nov 2001 17:57:06 -0500
User-agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/20.7 (i386-redhat-linux-gnu)

Mark Stosberg <address@hidden> wrote:
>         Paths held in standard environment variables that contain special
> characters could be handled more gracefully.
> Repeat-By:
>         mkdir "foo bar"
>         cd "foo bar"
>         cd $PWD
>         cd: /home/mark/tmp/foo: No such file or directory

By leaving $PWD unquoted, you told bash to perform word splitting on
its value.  If you don't want word splitting, use double quotes, just
as you did with the literal value.

>         To avoid this, path names could be stored quoted in the environment by
> default, like this:
>         PWD="/home/mark/tmp/foo bar"

That would not prevent word splitting, and it would be a completely
different path.  Those quotes would be part of the variable's value,
not syntactic quotes.  Thus the value would be incorrect: the name of
the directory is '/home/mark/tmp/foo bar', not
'"/home/mark/tmp/foo bar"'.

> Otherwise it would seem that every shell script that dealt with one
> of the path environment variables would have to be careful about
> quoting it correctly.

Right.  You might say that it's ugly that word splitting is performed
by default, and that the quoted behavior should be the default, with a
special operation used to split it.  I would agree, but the result
would be a different language.  It's impossible to do it without being
massively incompatible with traditional sh.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]