set path = "$path" hoses path in tcsh -- why???

set path = "$path" hoses path in tcsh -- why???

Post by adunca » Thu, 03 Dec 1998 04:00:00



All:

  % echo $path
  /usr/local/bin /usr/pubsw/bin /usr/bin ...
  % ls
  [... etc ... it works]
  % set path = "$path"   *** What the hell happens here??? ***
  % echo $path
  /usr/local/bin /usr/pubsw/bin /usr/bin ... looks the same
  % ls
  ls: Command not found.

This is just a particularly egregious illustration of the problem. In
general, if I try to do something like this:

  % set savedPath = "$path"  # Save current path
  % set path = "$savedPath"  # Restore saved path

it doesn't work. The path *looks* the same, but the shell can't find
anything. Recall that the shell variable path and the environment
variable PATH are linked, so setting one automatically sets the other
also. Some unexpected feature of list interpolation perhaps? Bug or
feature, I call it a pain...

Andrew Duncan

 
 
 

set path = "$path" hoses path in tcsh -- why???

Post by Barry Margoli » Thu, 03 Dec 1998 04:00:00




>All:

>  % echo $path
>  /usr/local/bin /usr/pubsw/bin /usr/bin ...
>  % ls
>  [... etc ... it works]
>  % set path = "$path"   *** What the hell happens here??? ***
>  % echo $path
>  /usr/local/bin /usr/pubsw/bin /usr/bin ... looks the same
>  % ls
>  ls: Command not found.

>This is just a particularly egregious illustration of the problem. In
>general, if I try to do something like this:

>  % set savedPath = "$path"  # Save current path
>  % set path = "$savedPath"  # Restore saved path

>it doesn't work. The path *looks* the same, but the shell can't find
>anything. Recall that the shell variable path and the environment
>variable PATH are linked, so setting one automatically sets the other
>also. Some unexpected feature of list interpolation perhaps? Bug or
>feature, I call it a pain...

The original path variable was a *list* -- if you look at the output of
"set", you'll see that it's printed in parentheses to indicate this.

When you do:

set path = "$path"

you turn that list into a single value.

The environment variable that the OS actually cares about is PATH, which is
a :-delimited list of directories.  Compare the contents of $PATH before
and after your assignment.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Don't bother cc'ing followups to me.

 
 
 

set path = "$path" hoses path in tcsh -- why???

Post by Bruce Barnet » Fri, 04 Dec 1998 04:00:00



>   % set path = "$path"   *** What the hell happens here??? ***

Use
        set path = ( $path )
instead. Enclosing the variable in "..." captures all of the spaces
in the variable. Normallt you do this:

% set path = ( $path )
% echo $#path
16

and this example has 16 directories in it's searchpath. If you did
this:

% set path = "$path"
% echo $?path
1

There would only be one directory in the searchpath.

This shows one of the problems with the C shell. (Reason #9 in my list)
Suppose I had three arguments to a list:
        set a = ( "a" "b c" "d" )

it becomes hard to copy this list without destroying information.
If I typed
        set b = "$a"
I only have one argument. If I type
        set b = ( $a )
then I have FOUR. If I type
        set b = $a
then b has one, but it is EMPTY!

--
Bruce  <barnett at crd. ge. com> (speaking as myself, and not a GE employee)

 
 
 

set path = "$path" hoses path in tcsh -- why???

Post by Hagen Ros » Sat, 05 Dec 1998 04:00:00


[snip]

Quote:> This shows one of the problems with the C shell. (Reason #9 in my list)
> Suppose I had three arguments to a list:
>    set a = ( "a" "b c" "d" )

> it becomes hard to copy this list without destroying information.
> If I typed
>    set b = "$a"
> I only have one argument. If I type
>    set b = ( $a )
> then I have FOUR. If I type
>    set b = $a
> then b has one, but it is EMPTY!

Remember that the C shell provides an other way to quote variables
besides using quotes, the :q modifier.  If you wrote

    set b = ( ${a:q} )

you would get a three element copy of variable a in variable b.  Not
too hard, IMHO.

--
Hagen Ross

 
 
 

set path = "$path" hoses path in tcsh -- why???

Post by Bruce Barnet » Wed, 09 Dec 1998 04:00:00



>     set b = ( ${a:q} )

Good point. I don't use :q very much.

--
Bruce  <barnett at crd. ge. com> (speaking as myself, and not a GE employee)