sh gets lost doing 'cd' to soft linked directory
Dan Watts
dwatts at ki.UUCP
Thu Dec 13 07:56:26 AEST 1990
I ran into a nasty little gotcha the other day while writing a Bourne shell
script. What happens is that I have soft linked directories. I need to be
able to cd into them, cd one level up to the _real_ directory that is above
the soft linked directory, and then I cd back to where I started from. This
process then repeats 'n' times. For the value of 'n' equal 0, it works fine.
For values > 0, it doesn't. Doing the 'cd ..' from the soft linked directory
does take me where I want, but the value displayed by 'pwd' is incorrect!
Below is my output. Note that I was origonally in 'csh' and I then execute
sh (or the shell script which says "#!/bin/sh" as the first line).
Anybody got any clues as to what's going on? I've rewritten my shell script
to be a C-Shell to get around it.
% sh
$ pwd
/usr/people/dwatts/tmp/bug <=== Where I start from
$ ls -l
total 2
l--------- 1 dwatts ki 6 Dec 12 14:46 RCS -> x1/RCS
-rw-rw---- 1 dwatts ki 0 Dec 12 15:25 This_is_bug
drwxrwx--- 3 dwatts ki 512 Dec 12 15:24 x1
$ cd RCS
$ pwd
/usr/people/dwatts/tmp/bug/x1/RCS <=== Where I wanted to go
$ ls -l
total 0
-rw-rw---- 1 dwatts ki 0 Dec 12 15:24 This_is_bug_x1_RCS
$ cd ..
$ pwd
/usr/people/dwatts/tmp/bug/x1 <=== So far so good
$ ls -l
total 1
drwxrwx--- 2 dwatts ki 512 Dec 12 15:24 RCS
-rw-rw---- 1 dwatts ki 0 Dec 12 15:24 This_is_bug_x1
$ cd /usr/people/dwatts/tmp/bug <=== And back to the starting place
$ pwd
/usr/people/dwatts/tmp/bug
$ ls -l <=== Looks ok to me
total 2
l--------- 1 dwatts ki 6 Dec 12 14:46 RCS -> x1/RCS
-rw-rw---- 1 dwatts ki 0 Dec 12 15:25 This_is_bug
drwxrwx--- 3 dwatts ki 512 Dec 12 15:24 x1
$ cd RCS <=== Let's do this a 2'nd time
$ pwd
/usr/people/dwatts/tmp/bug/RCS <=== Uh Oh! This isn't right!
$ ls -l <=== But the files are right
total 0
-rw-rw---- 1 dwatts ki 0 Dec 12 15:24 This_is_bug_x1_RCS
$ cd .. <=== Let's see what happens
$ pwd
/usr/people/dwatts/tmp/bug <=== Based upon the previous pwd, this
$ ls -l is correct. However, the ls
total 1 shows a totally different dir!
drwxrwx--- 2 dwatts ki 512 Dec 12 15:24 RCS
-rw-rw---- 1 dwatts ki 0 Dec 12 15:24 This_is_bug_x1
$ cd .. <=== Let's go up and see where we go
$ pwd
/usr/people/dwatts/tmp <=== The name is valid
$ ls -l <=== But we end end up seeing a
total 2 different directory again!
l--------- 1 dwatts ki 6 Dec 12 14:46 RCS -> x1/RCS
-rw-rw---- 1 dwatts ki 0 Dec 12 15:25 This_is_bug
drwxrwx--- 3 dwatts ki 512 Dec 12 15:24 x1
--
################## Skinny Dippers Have Less Stress ##################
# CompuServe: >INTERNET:uunet.UU.NET!ki!dwatts Dan Watts #
# UUCP : ...!{uunet | wgc386}!ki!dwatts Ki Research, Inc. #
############### New Dimensions In Network Connectivity ##############
More information about the Comp.sys.sgi
mailing list