[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: equivalent of Linux readlink -f in pure bash?
From: |
Stephane CHAZELAS |
Subject: |
Re: equivalent of Linux readlink -f in pure bash? |
Date: |
Tue, 9 Aug 2011 10:24:40 +0100 |
User-agent: |
slrn/pre1.0.0-18 (Linux) |
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() (
link=$1 max_iterations=40
while [ "$max_iterations" -gt 0 ]; do
max_iterations=$(($max_iterations - 1))
dir=$(dirname -- "$link") || exit
base=$(basename -- "$link") || exit
dir=$(cd -P -- "$dir" && pwd -P) || exit
link=${dir%/}/$base
if [ ! -L "$link" ]; then
printf '%s\n' "$link"
exit
fi
link=$(ls -ld -- "$link") || exit
link=${link#* -> }
done
printf >&2 'Loop detected\n'
exit 1
)
--
Stephane
Message not available
Re: equivalent of Linux readlink -f in pure bash?,
Stephane CHAZELAS <=