[comp.unix.xenix] "cd path" strangeness

chip@vector.UUCP (Chip Rosenthal) (06/05/88)

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".

The expected response would be "path: No such file or directory."  Instead,
no message is issued, and either you stay where you were or you move to
$path[1].  This behavior is independant of the definition of "cdpath" (or
lack of definition).

I've seen this on both SCO XENIX and SysV on an Edge.  Now I'm trying to
figure out whether it is refreshing or frustrating that XENIX is close
enough to SysV to replicate it bug for bug.
-- 
Chip Rosenthal /// chip@vector.UUCP /// Dallas Semiconductor /// 214-450-0400
{uunet!warble,sun!texsun!rpp386,killer}!vector!chip
I won't sing for politicians.  Ain't singing for Spuds.  This note's for you.

ekrell@hector.UUCP (Eduardo Krell) (06/05/88)

In article <337@vector.UUCP> chip@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".

>The expected response would be "path: No such file or directory."  Instead,
>no message is issued, and either you stay where you were or you move to
>$path[1].  This behavior is independant of the definition of "cdpath" (or
>lack of definition).

This is documented in the man page for csh (at least in 4.3 BSD).
When everything else fails, cd checks to see whether there's an environment
variable whose name is the same as the argument you typed. If the
value of that variable is a string and starts with a "/", then it
takes that as the directory to cd to.
    
    Eduardo Krell                   AT&T Bell Laboratories, Murray Hill, NJ

    UUCP: {ihnp4,ucbvax}!ulysses!ekrell		ARPA: ekrell@ulysses.att.com

gwyn@brl-smoke.ARPA (Doug Gwyn ) (06/05/88)

In article <337@vector.UUCP> chip@vector.UUCP (Chip Rosenthal) writes:
-Here is a wierd one.  In csh, ...
-Now I'm trying to figure out whether it is refreshing or frustrating
-that XENIX is close enough to SysV to replicate it bug for bug.

Since csh is not part of UNIX System V, this is nonsense.

jl42+@andrew.cmu.edu (Jay Mathew Libove) (06/14/88)

I tried Chip Salzenberger's "cd path" command on Berkeley Unix 4.3 and
on CMU Mach 4.3, and got the same strangeness he described;
So, I looked at "man csh" and found:
(reproduced without permission from csh.1, CMU mach 4.3)

>cd
>cd name
>chdir
>chdir name
> Change the shell's working directory to directory "name".
> If no argument is given then change to the home directory of
> the user.
> If "name" is not found as a subdirectory of the current directory
> (and does not begin with `/', `./' or `../'), then each component
> of the variable "cdpath" is checked to see if it has a subdirectory
> "name". Finally, if all else fails but "name" is a shell variable
> whose value begins with `/', then this is tried to see if it is a
> directory.

That last item, "if all else fails but "name" is a shell variable"...
Well, most of us have "path" set to something beginning with a /
right? There you go....

This is NOT a bug :-)

Jay Libove
Arpa:   Jay.Libove@andrew.cmu.edu	Bitnet: Jay.Libove@drycas.bitnet
UUCP:   ...!{uunet, ucbvax, harvard}!andrew.cmu.edu!Jay.Libove
UUCP:   ...!{pitt | bellcore} !darth!libove!libove

jbush@ficc.UUCP (james bush) (06/16/88)

In article <337@vector.UUCP>, chip@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".
> 
> The expected response would be "path: No such file or directory."  Instead,
> no message is issued, and either you stay where you were or you move to
> $path[1]...

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.
-- 
James Bush, Ferranti, Houston                         Praise the Lord
Internal address: jbush  extension 5230, mail stop A/3204, room A/3602
External address: ..!uunet!nuchat!sugar!ficc!jbush

ljz@fxgrp.UUCP (Lloyd Zusman) (06/17/88)

In article <922@.UUCP> jbush@ficc.UUCP (james bush) writes:
  In article <337@vector.UUCP>, chip@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@ames.arc.nasa.gov
  Los Gatos, California               or try:   fxgrp!ljz@ames.arc.nasa.gov
  "We take things well in hand."

maujd@warwick.UUCP (Geoff Rimmer) (06/21/88)

In article <337@vector.UUCP> chip@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".
>
>The expected response would be "path: No such file or directory."  Instead,
>no message is issued, and either you stay where you were or you move to
>$path[1].  This behavior is independant of the definition of "cdpath" (or
>lack of definition).
>

Let me quote from the manual page for csh!

cd [dir]
chdir [dir]
	Change the shell's working directory to directory dir.  If no
	argument is given, change to the home directory of the user.
	If dir is a relative path-name not found in the current
	directory, check for it in those directories listed in the
	cdpath variable.  If dir is the name of a shell variable whose
	value starts with a /, change to the directory named by that value.

i.e. the argument after the 'cd' or 'chdir' is checked:-

	1	for a directory given by a relative pathname
	2	for a directory in cdpath
	3	for a directory taken from the shell variable

so, since #1,2 fail with your example ('cd path'), #3 is used, and so
the directory is changed to $path[1] - it seems if you give it a
variable that contains more than one directory, such as $path, it
takes the first one.

>-- 
>Chip Rosenthal /// chip@vector.UUCP /// Dallas Semiconductor /// 214-450-0400
>{uunet!warble,sun!texsun!rpp386,killer}!vector!chip
>I won't sing for politicians.  Ain't singing for Spuds.  This note's for you.

	------------------------------------------------------------
	Geoff Rimmer, Computer Science, Warwick University, UK.
			maujd@uk.ac.warwick.opal

	"I report the news as it's seen in my country" - CNN
	------------------------------------------------------------

maujd@warwick.UUCP (Geoff Rimmer) (06/27/88)

In article <922@.UUCP> jbush@ficc.UUCP (james bush) writes:
>In article <337@vector.UUCP>, chip@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".
>> 
>> The expected response would be "path: No such file or directory."  Instead,
>> no message is issued, and either you stay where you were or you move to
>> $path[1]...
>
>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.

Perhaps he uses Bourne shell?  

extravagent_prompt % sh
$ cd path
path: bad directory
$

No flames please - term finishes in under a week - so I won't be here
to read them 8-)

Geoff.

>James Bush, Ferranti, Houston                         Praise the Lord
>Internal address: jbush  extension 5230, mail stop A/3204, room A/3602
>External address: ..!uunet!nuchat!sugar!ficc!jbush

	-----------------------------------------------------------------
	Geoff Rimmer, Computer Science, Warwick University, UK.
			maujd@uk.ac.warwick.opal

	"I do SMILE humour - people aren't SUPPOSED to laugh."
	"Yeah, but they aren't supposed to throw heavy objects 
	 and shout 'Get off you boring bastard, we've heard better
	            jokes on the speaking clock!'"

		- Filthy Rich and Catflap (BBC TV)
	(Get your local TV station to buy this excellent comedy series!!)
	-----------------------------------------------------------------