help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determing intermediate symlinked name in a Bash script


From: Paul Jarc
Subject: Re: Determing intermediate symlinked name in a Bash script
Date: Mon, 22 Nov 2004 11:29:08 -0500
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux)

Nate Bargmann <n0nb@networksplus.net> wrote:
> I want to figure out from inside the script 'junk' whether 'redirect'
> points to 'foo' or 'bar' so 'junk' can take appropriate action.

If your system has the readlink command: readlink "$0"
Otherwise, you can reimplement that command in Perl, etc.:

readlink() { perl -le 'print(readlink($ARGV[0]) or die($!."\n"))' "$1"; }
readlink() { python -c 'import sys, os; print os.readlink(sys.argv[1])' "$1"; }
readlink() {
  guile -c '(format #t "~A\n" (readlink (cadr (program-arguments))))' "$1"
}

> There must be some way that the shell "knows" by following the
> symlinks whether 'foo' or 'bar' was in the chain.

The shell doesn't need to know.  It just opens and reads "redirect",
and the *kernel* follows the symlink chain.


paul




reply via email to

[Prev in Thread] Current Thread [Next in Thread]