[comp.unix.questions] Symbolic links and Bourne shell...

boysko@dsrgsun.CES.CWRU.Edu (Glenn Boysko) (09/07/90)

In Bourne shell, how can you find the path pointed to be a symbolic link?

In C shell, you can type:

	% set linkpath = "`cd $SYMLINK; pwd`"

However, in Bourne shell, pwd returns the same value as SYMLINK.  Does anyone
know how to get this info in a Bourne shell without typing:

	% linkpath="`csh -c 'cd $SYMLINK; pwd'`"


Thanks,
Glenn

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Glenn Boysko		clsi!glenn@uunet.uu.net

gwyn@smoke.BRL.MIL (Doug Gwyn) (09/07/90)

In article <1990Sep7.140159.4832@usenet.ins.cwru.edu> boysko@dsrgsun.CES.CWRU.Edu (Glenn Boysko) writes:
>In Bourne shell, how can you find the path pointed to be a symbolic link?
>However, in Bourne shell, pwd returns the same value as SYMLINK.

That depends on the Bourne shell implementation.  I normally configure
ours to work like that, because it is more in line with what I think
is a sensible user model for how symlinks to directories should be used.
When I want to find the "real" CWD (i.e. one not involving any symlink
components), I use /bin/pwd instead of the shell's built-in "pwd" command.

merlyn@iwarp.intel.com (Randal Schwartz) (09/08/90)

In article <1990Sep7.140159.4832@usenet.ins.cwru.edu>, boysko@dsrgsun (Glenn Boysko) writes:
| In Bourne shell, how can you find the path pointed to be a symbolic link?
| However, in Bourne shell, pwd returns the same value as SYMLINK.  Does anyone
| know how to get this info in a Bourne shell without typing:
| 
| 	% linkpath="`csh -c 'cd $SYMLINK; pwd'`"

I use /bin/pwd, as in:

	(cd /SOMEWHERE/THAT/MAY/BE/A/SYMLINK; /bin/pwd)

which avoids any builtin pwd command (in either sh or csh) that may be
fooled by the presence of symlinks.

I also have a script (in Perl, natch) that expands symlinks step by
step to tell me how "expensive" they are (we had a lot of off-machine
symlinks that were pointing to other possibly on-machine directories
that were causing a lot of net traffic).

Just another Unix hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

cpcahil@virtech.uucp (Conor P. Cahill) (09/08/90)

In article <1990Sep7.140159.4832@usenet.ins.cwru.edu> boysko@dsrgsun.CES.CWRU.Edu (Glenn Boysko) writes:
>
>In C shell, you can type:
>	% set linkpath = "`cd $SYMLINK; pwd`"
>However, in Bourne shell, pwd returns the same value as SYMLINK.  Does anyone
>know how to get this info in a Bourne shell without typing:

Have you tried:

 	% linkpath="`cd $SYMLINK; /bin/pwd'`"

The moral of the story is that pwd is a built-in (in many borne shells) that
just echos what the shell thinks is the current directory.

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 

jeff@onion.pdx.com (Jeff Beadles) (09/09/90)

boysko@dsrgsun.CES.CWRU.Edu (Glenn Boysko) writes:
>
>In Bourne shell, how can you find the path pointed to be a symbolic link?
>
>In C shell, you can type:
>
>	% set linkpath = "`cd $SYMLINK; pwd`"
>
>However, in Bourne shell, pwd returns the same value as SYMLINK.  Does anyone
>know how to get this info in a Bourne shell without typing:
>
>	% linkpath="`csh -c 'cd $SYMLINK; pwd'`"

Well, here's a different way.  The 'ls' command has an option 'L' that should
tell you the information that you need.  An excerpt from TFM...

...
     -L If argument is a symbolic link, list the file or
        directory the link references rather than the link
        itself.
...

Ie:
	% touch /usr/tmp/foo
	% ln -s /usr/tmp/foo ./bar
	% ls -L ./bar
	/usr/tmp/foo
	% ^D

Your mileage may vary.  I know that this does not work on all systems.  4.3BSD
is broken. :-(

If you have this option, you can do the following:
	linkpath="`ls -L $SYMLINK`"

	-Jeff
-- 
Jeff Beadles  jeff@onion.pdx.com  jeff@quark.wv.tek.com

nwosuck@aix.aix.kingston.ibm.com (Kingsley Nwosu) (10/11/90)

In article <1990Sep7.140159.4832@usenet.ins.cwru.edu> you write:
>
>In Bourne shell, how can you find the path pointed to be a symbolic link?
>
>In C shell, you can type:
>
>	% set linkpath = "`cd $SYMLINK; pwd`"
>
>However, in Bourne shell, pwd returns the same value as SYMLINK.  Does anyone
>know how to get this info in a Bourne shell without typing:
>
>	% linkpath="`csh -c 'cd $SYMLINK; pwd'`"


I don't understand your problem.

In Bourne shell, one can do:

         $ linkpath=`cd $SYMBOLIC;pwd`

I know I can. Why can't you?

Aahhh! Maybe implementation differences!!!!



Kingsley Nwosu			   ...uunet!ibmps2!aix!nwosuck
IBM AIX  Dev., Dept. 83HA/572,  |
Neighborhood Rd, Kingston,      |"Advice to those about to get married: Don't!"
NY 12401.			|	 

gt0178a@prism.gatech.EDU (Jim Burns) (10/12/90)

> In article <1990Sep7.140159.4832@usenet.ins.cwru.edu> you write:

>>In Bourne shell, how can you find the path pointed to be a symbolic link?

>>In C shell, you can type:

>>	% set linkpath = "`cd $SYMLINK; pwd`"

>>However, in Bourne shell, pwd returns the same value as SYMLINK.  Does anyone

Try:

linkpath=`cd $SYMLINK; /bin/pwd`

-- 
BURNS,JIM
Georgia Institute of Technology, Box 30178, Atlanta Georgia, 30332
uucp:	  ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt0178a
Internet: gt0178a@prism.gatech.edu