"cd path" strangeness

Lloyd Zusman ljz at fxgrp.UUCP
Fri Jun 17 06:16:36 AEST 1988


In article <922 at .UUCP> jbush at ficc.UUCP (james bush) writes:
  In article <337 at vector.UUCP>, chip at vector.UUCP (Chip Rosenthal) writes:
  > Here is a wierd one.  In csh, move to some directory which doesn't have
  > a "path" subdirectory.  Then type either "cd path" or "chdir path".
  > ...

  This is even more wierd. I tried it on our Intel Xenix system, and it worked
  as you said when I did it under my login.  However, when I tried to show it 
  to my friend under his id, it came up with the "expected" error message! I
  am not sure what the difference is.

The wierd behavior described by Mr. Rosenthal is due to a little
known feature of the C shell:

If a shell variable is set to a value whose first character is a "/",
it can be used with cd without the leading dollar sign.  For example,
suppose you have done the following:

    set foo = /a/b/c/d/e

Then, the next two lines will have the exact same behavior:

    cd $foo
    cd foo

Here's the description in our csh man page:

     cd [dir]
     chdir [dir]
               Change the shell's working directory to  directory
               dir.   ...
    	       ...     If  dir  is  the  name of a shell variable
               whose value starts with a /, change to the  direc-
               tory named by that value.

Note that this works only with shell variables, not environment variables.

The wierd behavior described by Mr. Bush might be due to the fact that
his 'path' variable's first entry begins with a "/", while his friend's
'path' variable doesn't.

--
  Lloyd Zusman                          UUCP:   ...!ames!fxgrp!ljz
  Master Byte Software              Internet:   ljz%fx.com at ames.arc.nasa.gov
  Los Gatos, California               or try:   fxgrp!ljz at ames.arc.nasa.gov
  "We take things well in hand."



More information about the Comp.unix.questions mailing list