Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: checking link files - recursive search
- X-seq: zsh-users 11688
- From: "Matt Wozniski" <godlygeek@xxxxxxxxx>
- To: linux_milano@xxxxxxxx, zsh-users@xxxxxxxxxx
- Subject: Re: checking link files - recursive search
- Date: Sun, 29 Jul 2007 17:13:50 -0400
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=oZRlAxlLBkH7zNgE8qQEpqx0tV/EGqnAoXHybF7KEXHgQh4M+vkvJCYjdtiCVzJuqkOuF9zNwFLSaNVxDZaO4C6GMK0jLPpBMxz5/CLxnB32kLhJbpOqlpE/OYX3vWdrcgfb9pkI72J2Hm/ivlRgIY+MMW3N15oCwUHZiH3Kyks=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=C+wWhMtKX46wLSpdSLEmLEXa+MAX6En2LyMZIMM002FR9AECddLCl/vRVSX7NtnP/QWTubyZkQo7js4brm4zXWtK/hapDKyusrMZ1K5LX7KcCTcc22CN+AvgBoZ7SZyXNFlYA5clIf9jyLH92KO8ZbcqvHN3uaWeaMHO5elmEJQ=
- In-reply-to: <f8hok7$kol$1@xxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <f8gnpp$b2f$1@xxxxxxxxxxxxx> <17393e3e0707281851g6e6e6f30y451fc31a031cfbaa@xxxxxxxxxxxxxx> <f8hok7$kol$1@xxxxxxxxxxxxx>
I'm assuming you meant for this response to go to the list, so I'm
replying there.
On 7/29/07, pol <linux_milano@xxxxxxxx> wrote:
> Matt Wozniski wrote:
>
> > On 7/28/07, pol <linux_milano@xxxxxxxx> wrote:
> > so, you should be able to just use
> > file=$(readlink -f "$file")
> > assuming you'd like to resolve links recursively, so that a link to a
> > link to a file resolves to the file and not the middle link.
>
> You are right, my script does not perform recursive search, as i would.
> Using readlink would be a solution.
> I am wondering whether Zsh can meet that request internally, without
> resorting to external programs
function resolve_recursive {
(
while :; do
cd $1:h
local file=$1:t
file=$(stat -L +link $file)
if [ -z "$file" ]; then
echo $PWD/$1:t
break
fi
argv[1]=$file
done
)
}
The cd's are the simplest way I could think of to handle symlinks
using relative paths to different directories. The enclosing '(' and
')' make the entire function execute in a subshell, so that your
actual PWD isn't modified. When it resolves the file completely, it
prints out the absolute path to it and exits.
~Matt
Messages sorted by:
Reverse Date,
Date,
Thread,
Author