On a GNU system I would just use readlink -f $SOME_PATH
, but Solaris doesn't have readlink.
I'd prefer something that works well in bash, but other programs are ok if needed.
Edit: The best I've come up with so far uses cd and pwd, but requires some more hackery to deal with files and not just directories.
cd -P "$*"
REAL_PATH=`pwd`
Might be overkill, but this is OS portable, and does not need to find the dirname nor basename binaries first.. this one-liner works. Just pass in your filename where you see $origFile:
perl -e "use Cwd realpath; print realpath(\"$origFile\");"
Does this help? From the referenced page:
Create a file called canonicalize
with these contents:
#!/bin/bash
cd -P -- "$(dirname -- "$1")" &&
printf '%s\n' "$(pwd -P)/$(basename -- "$1")"
Make the file executable:
chmod +x canonicalize`
And finally:
user@host$ canonicalize ./bash_profile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With