Re: equivalent of Linux readlink -f in pure bash?

2012-01-10 Thread Chet Ramey
However, this also loops endlessly. The reason is most likely that bash maintains an additional internal variable holding the index of the current character, relative to the current word. While this variable is not directly accessible by the user, it is set to 0 whenever OPTIND is

Re: equivalent of Linux readlink -f in pure bash?

2012-01-09 Thread Clark J. Wang
On Wed, Aug 10, 2011 at 18:47, Stephane CHAZELAS stephane_chaze...@yahoo.fr wrote: 2011-08-10, 12:00(+02), Bernd Eggink: [...] function f { local OPTIND=1 echo \$1=$1 } while getopts abcdefg opt do echo opt=$opt f $opt done

Re: equivalent of Linux readlink -f in pure bash?

2011-08-11 Thread Clark J. Wang
On Wed, Aug 10, 2011 at 6:00 PM, Bernd Eggink mono...@sudrala.de wrote: On 09.08.2011 15:50, Steven W. Orr wrote: *) You reset OPTIND to 1 but you didn't declare it local. This will cause any caller of getlink which uses getopts to reset its variable to 1. (I mention this because it cost me

Re: equivalent of Linux readlink -f in pure bash?

2011-08-11 Thread Stephane CHAZELAS
2011-08-9, 09:24(+00), Stephane CHAZELAS: 2011-08-9, 11:44(+10), Jon Seymour: Has anyone ever come across an equivalent to Linux's readlink -f that is implemented purely in bash? (I need readlink's function on AIX where it doesn't seem to be available). [...] What about: readlink_f() (

Re: equivalent of Linux readlink -f in pure bash?

2011-08-11 Thread Stephane CHAZELAS
2011-08-09, 11:29(+02), Bernd Eggink: On 09.08.2011 03:44, Jon Seymour wrote: Has anyone ever come across an equivalent to Linux's readlink -f that is implemented purely in bash? You can find my version here: http://sudrala.de/en_d/shell-getlink.html As it contains some corrections

Re: equivalent of Linux readlink -f in pure bash?

2011-08-11 Thread Bernd Eggink
On 09.08.2011 16:54, Stephane CHAZELAS wrote: 2011-08-09, 09:50(-04), Steven W. Orr: [...] *) To remove the trailing slashes, instead of while [[ $file == */ ]] do file=${file%/} done file=${file##*/}# file name

Re: equivalent of Linux readlink -f in pure bash?

2011-08-10 Thread Bernd Eggink
On 09.08.2011 15:50, Steven W. Orr wrote: On 8/9/2011 5:29 AM, Bernd Eggink wrote: On 09.08.2011 03:44, Jon Seymour wrote: Has anyone ever come across an equivalent to Linux's readlink -f that is implemented purely in bash? You can find my version here:

Re: equivalent of Linux readlink -f in pure bash?

2011-08-09 Thread Andreas Schwab
Bob Proulx b...@proulx.com writes: Same comment here about over-quoting. If nothing else it means that syntax highlighting is different. dir=$(cd $(dirname $path); pwd -P) You are missing a pair of quotes here. :-) Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key

Re: equivalent of Linux readlink -f in pure bash?

2011-08-09 Thread Bernd Eggink
On 09.08.2011 03:44, Jon Seymour wrote: Has anyone ever come across an equivalent to Linux's readlink -f that is implemented purely in bash? You can find my version here: http://sudrala.de/en_d/shell-getlink.html As it contains some corrections from Greg Wooledge, it should handle

Re: equivalent of Linux readlink -f in pure bash?

2011-08-09 Thread Steven W. Orr
On 8/9/2011 5:29 AM, Bernd Eggink wrote: On 09.08.2011 03:44, Jon Seymour wrote: Has anyone ever come across an equivalent to Linux's readlink -f that is implemented purely in bash? You can find my version here: http://sudrala.de/en_d/shell-getlink.html As it contains some corrections from

Re: equivalent of Linux readlink -f in pure bash?

2011-08-09 Thread Jon Seymour
On Tue, Aug 9, 2011 at 7:29 PM, Bernd Eggink mono...@sudrala.de wrote: On 09.08.2011 03:44, Jon Seymour wrote: Has anyone ever come across an equivalent to Linux's readlink -f that is implemented purely in bash? You can find my version here:        http://sudrala.de/en_d/shell-getlink.html

equivalent of Linux readlink -f in pure bash?

2011-08-08 Thread Jon Seymour
Has anyone ever come across an equivalent to Linux's readlink -f that is implemented purely in bash? (I need readlink's function on AIX where it doesn't seem to be available). jon.

Re: equivalent of Linux readlink -f in pure bash?

2011-08-08 Thread Jon Seymour
On Tue, Aug 9, 2011 at 12:49 PM, Bob Proulx b...@proulx.com wrote: Jon Seymour wrote: Has anyone ever come across an equivalent to Linux's readlink -f that is implemented purely in bash? (I need readlink's function on AIX where it doesn't seem to be available). Try this:  ls -l

Re: equivalent of Linux readlink -f in pure bash?

2011-08-08 Thread Bob Proulx
Jon Seymour wrote: readlink -f will fully resolve links in the path itself (rather than link at the end of the path), which was the behaviour I needed. Ah, yes, well, as you could tell that was just a partial solution anyway. It seems cd -P does most of what I need for directories and so

Re: equivalent of Linux readlink -f in pure bash?

2011-08-08 Thread Jon Seymour
On Tue, Aug 9, 2011 at 1:36 PM, Bob Proulx b...@proulx.com wrote: Jon Seymour wrote: readlink -f will fully resolve links in the path itself (rather than link at the end of the path), which was the behaviour I needed. Ah, yes, well, as you could tell that was just a partial solution anyway.

Re: equivalent of Linux readlink -f in pure bash?

2011-08-08 Thread Bob Proulx
Jon Seymour wrote: I always use sed for this purpose, so: $(cd $dir; ls -l $base | sed s/.*-//) But, with pathological linking structures, this isn't quite enough - particularly if the target of the link itself contains paths, some of which may contain links :-) Agreed! Symlinks with

Re: equivalent of Linux readlink -f in pure bash?

2011-08-08 Thread Jon Seymour
On Tue, Aug 9, 2011 at 2:14 PM, Bob Proulx b...@proulx.com wrote: Jon Seymour wrote: I always use sed for this purpose, so:    $(cd $dir; ls -l $base | sed s/.*-//) But, with pathological linking structures, this isn't quite enough - particularly if the target of the link itself contains

Re: equivalent of Linux readlink -f in pure bash?

2011-08-08 Thread Jon Seymour
On Tue, Aug 9, 2011 at 2:36 PM, Jon Seymour jon.seym...@gmail.com wrote: On Tue, Aug 9, 2011 at 2:14 PM, Bob Proulx b...@proulx.com wrote: Jon Seymour wrote: I always use sed for this purpose, so:    $(cd $dir; ls -l $base | sed s/.*-//) But, with pathological linking structures, this isn't

Re: equivalent of Linux readlink -f in pure bash?

2011-08-08 Thread Bob Proulx
Jon Seymour wrote: readlink_f() { local path=$1 test -z $path echo usage: readlink_f path 12 exit 1; An extra ';' there that doesn't hurt but isn't needed. local dir if test -L $path then local link=$(ls -l $path | sed s/.*- //)

Re: equivalent of Linux readlink -f in pure bash?

2011-08-08 Thread Jon Seymour
On Tue, Aug 9, 2011 at 2:51 PM, Bob Proulx b...@proulx.com wrote: Jon Seymour wrote: readlink_f() {         local path=$1         test -z $path echo usage: readlink_f path 12 exit 1; An extra ';' there that doesn't hurt but isn't needed.         local dir         if test -L $path