## resolve_path - recursively resolve path with sym links ## Type "FPATH=/path/to/resolve_path; resolve_path help=y" for man page. function resolve_path { typeset OPATH=$PATH HELP SHOW VERBOSE ## typeset PATH i ipath typeset -u _I for i; do if [[ $i == *=* ]]; then _I=$i; eval $_I else ipath=$i fi done # SKIP_B [[ $HELP == Y || $SHOW == Y ]] && { typeset -x PATH=$OPATH typeset me=resolve_path # $0 in ksh93; not available for showme(). function showme { typeset fp=$1 typeset me=$2 typeset i for i in $(IFS=:; print "$fp"); do [[ -r $i/$me ]] && cat $i/$me && break done } [[ $HELP == Y ]] && { typeset tempfile=/tmp/$me.$$.$RANDOM rm -f $tempfile trap "rm -f $tempfile" EXIT INT showme $FPATH $me | sed -n "/^##/s:^## \{0,1\}::p" > $tempfile perldoc $tempfile } [[ $SHOW == Y ]] && { showme $FPATH $me | sed "/^# SKIP_B/,/^# SKIP_E/d; /^##/d; /##$/d" } return 0 } # SKIP_E typeset j PERL for j in /usr/bin/perl /bin/perl /usr/local/bin/perl; do [[ -x $j ]] && PERL=$j && break done typeset d f s="set" [[ $VERBOSE == Y ]] && print "$ipath" while [[ -n "$s" ]]; do j=${ipath%/*} [[ -z $j ]] && j=/ d=$(cd $j >/dev/null && pwd -P) f=${ipath##*/} s=$($PERL -e "print(STDOUT readlink(\"$ipath\"));") if [[ -n "$s" ]]; then if [[ $s == /* ]]; then ipath=$s else ipath=$d/$s fi [[ $VERBOSE == Y ]] && print "$ipath" else ipath=$d/$f && print "$ipath" fi done } ## =head1 NAME ## ## resolve_path - recursively resolve path with sym links ## ## =head1 SYNOPSIS ## ## FPATH=/path/to/resolve_path ## resolve_path symlink [verbose=y] [help=y] [show=y] ## ## =head1 DESCRIPTION ## ## B takes the path with sym links, ## write out the converted fully resolved path to stdout. ## ## If "help=y" is part of the arguments, the man page is shown. If ## the arguments include "show=y", then the function itself is displayed, ## which can be statistically included in other programs. If "verbose=y" ## option is used, the steps in resolving the path is shown. ## ## =head1 EXAMPLE ## ## $ resolve_path /tmp/system ## /tmp/export/redirect/ora02/system ## ## $ resolve_path /tmp/system verbose=y ## /tmp/system ## /tmp/export/ora01/system ## /tmp/export/redirect/ora01/../ora02/system ## /tmp/export/redirect/ora02/system ## ## =head1 SEE ALSO ## ## ls(1), Perl readlink(). ## ## =head1 AUTHORS ## ## Michael Wang >. ## ## This is free software. You may copy or redistribute it under the same ## terms as Perl. ## ## If you modify it, you are required to send a copy of the modification to ## me via email.