[ale] bash, full filename

Stuffed Crust pizza at shaftnet.org
Sun Nov 30 17:46:36 EST 2003


On Sun, Nov 30, 2003 at 02:42:17PM -0500, Jason Day wrote:
> > How can I take a filename (which may or may not be relative) and convert it to 
> > be a fully qualified filename, in bash?
> 
> If you can write a bit of C code and use an extra executable, there is a
> function in libc called realpath that does exactly what you want.  See
> man realpath for more info.

CHAR=`expr substr $file 1 1`
case $CHAR in 
	'/') 
		echo $file
		;;
	*)
	 	echo ${PWD}/$file
		;;
esac

A little more trickery is neessary if the relative path has ".." or "." 
in it (and you want to collapse it) but the path is otherwise still 
valid.

 - Pizza
-- 
Solomon Peachy                                   pizza at f*cktheusers.org
                                                           ICQ #1318444
Quidquid latine dictum sit, altum viditur                 Melbourne, FL
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available




More information about the Ale mailing list