[aklug] Re: relative to absolute path

From: Jim MacDonald <jim@macdonald.org>
Date: Tue Aug 26 2008 - 23:06:52 AKDT

in Bash

do

###############################
# fullpath.sh
# Given a relative path, create a full path.

# check for one arg
if [ $# -ne 1 ]; then
        echo "Usage : $0 {relative path}"
        exit -1
fi

# check to see if $1 exists
if [ -e $1 ]; then
        B=`basename $1`
        P=`dirname $1`
        # echo BASE:$B PATH:$P
        cd $P
        
        if [ `pwd` != "/" ]
        then
                FULLNAME=`pwd`/$B
        else
                FULLNAME=/$B
        fi
        
        echo $FULLNAME
else
        echo "$1 - Not a regular file"
        exit -1
fi

##########################################

see http://www.ale.org/pipermail/ale/20031130/003823.html for details.

Jim

William Attwood wrote:
> What operating system?
> On Tue, Aug 26, 2008 at 11:50 PM, <bryanm@acsalaska.net> wrote:
>
>
>> I really, really should know this, but I can't come up with the
>> trick. What shell trick can I use to print a file's full pathname?
>> For example, if I specify dir/file or ~/file or just file, how can
>> I turn that into the full path?
>>
>> --
>> Bryan Medsker
>> bryanm@acsalaska.net
>>
>> ---------
>> To unsubscribe, send email to <aklug-request@aklug.org>
>> with 'unsubscribe' in the message body.
>>
>>
>>
>
>
> ---------
> To unsubscribe, send email to <aklug-request@aklug.org>
> with 'unsubscribe' in the message body.
>
>
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Tue Aug 26 23:07:13 2008

This archive was generated by hypermail 2.1.8 : Tue Aug 26 2008 - 23:07:14 AKDT