* Finding symbolic links that are outside a tree (comp.unix.shell)
@ 2005-06-07 16:01 Thorsten Kampe
2005-06-07 17:39 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Kampe @ 2005-06-07 16:01 UTC (permalink / raw)
To: zsh-users
Hi, this has originally been posted to comp.unix.shell by "rh0dium
<sklass@pointcircle.com" and I couldn't find a solution for zsh.
So can this be done with zsh globbing? I couldn't get any further as
"print -l **/*(@)" which prints only symbolic links but doesn't do
anything for "that are outside a tree".
Thorsten
******************************************************************
Can anyone help me with a simple script to find links ouside of a
tree.
What I want is given the following tree two results would show up
tree
a
1 -> ../b
2
b
1 -> ../../../foo
2 -> ../c/1
c
1 ->/foo/bar
2
So I would expect 2 results
b1 and c1 should be the output. I just can't think of a slick way to
script this. Anyone care to offer a bit of assistance?
I'd love a zsh function or bash function which does this.
******************************************************************
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Finding symbolic links that are outside a tree (comp.unix.shell)
2005-06-07 16:01 Finding symbolic links that are outside a tree (comp.unix.shell) Thorsten Kampe
@ 2005-06-07 17:39 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2005-06-07 17:39 UTC (permalink / raw)
To: zsh-users
On Jun 7, 5:01pm, Thorsten Kampe wrote:
} Subject: Finding symbolic links that are outside a tree (comp.unix.shell)
}
} So can this be done with zsh globbing? I couldn't get any further as
} "print -l **/*(@)" which prints only symbolic links but doesn't do
} anything for "that are outside a tree".
I'm not entirely sure I understand the question, but I *think* the
answer is to begin with something like
function follow () {
stat -A reply +link $REPLY
if [[ $reply != /* ]]
then reply=( $PWD/$reply )
fi
}
zmodload -i zsh/stat
declare -a links
links=( **/*(@+follow) )
links=( ${links#$PWD/} )
integer n=${(@)#${(s:/:)PWD}}
Then walk the $links array and print every entry that begins with a slash
or has more leading ../ than the value of $n.
For older versions of zsh you need
links=( **/*(@e:follow:) )
instead of the +follow shorthand.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-06-07 17:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-07 16:01 Finding symbolic links that are outside a tree (comp.unix.shell) Thorsten Kampe
2005-06-07 17:39 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).