Canonicalize the path name on Solaris

On a GNU system, I would just use readlink -f $SOME_PATH , but Solaris does not have readlink.

I would prefer something that works well in bash, but if necessary, other programs are fine.

Edit: The best I've used so far is using cd and pwd, but requires a few more hackers to work with files, not just directories.

 cd -P "$*" REAL_PATH=`pwd` 
+4
source share
3 answers

Does this help? On the link page:

Create a file called canonicalize with this content:

 #!/bin/bash cd -P -- "$(dirname -- "$1")" && printf '%s\n' "$(pwd -P)/$(basename -- "$1")" 

Make an executable file:

 chmod +x canonicalize` 

And finally:

 user@host $ canonicalize ./bash_profile 
+3
source

It may be superfluous, but this OS is portable, and it does not need to search for dirname or basename files first. This single line file works. Just go to your name, where you will see $ origFile:

perl -e "use Cwd realpath; print realpath (\" $ origFile \ ");"

+5
source
 #!/bin/bash # Resolves a full path # - alternative to "readlink -f", which is not available on solaris canonicalpath() { if [ -d $1 ]; then pushd $1 > /dev/null 2>&1 echo $PWD elif [ -f $1 ]; then pushd $(dirname $1) > /dev/null 2>&1 echo $PWD/$(basename $1) else echo "Invalid path $1" fi popd > /dev/null 2>&1 } 
+1
source

All Articles