Given an arbitrary single argument representing a file (or directory, device, etc), how do I get the absolute path of the argument?
I've seen many answers to this question involving find/ls/stat/readlink and $PWD, but none that suits my need. It looks like the closest answer is ksh's "whence" command, but I need it to work in sh/bash.
Assume a file, foo.txt, is located in my home directory, /Users/matthew/foo.txt. I need the following behavior, despite what my current working directory is (I'm calling the command "abs"):
(PWD is ~)
$ abs foo.txt
/Users/matthew/foo.txt
$ abs ~/foo.txt
/Users/matthew/foo.txt
$ abs ./foo.txt
/Users/matthew/foo.txt
$ abs /Users/matthew/foo.txt
/Users/matthew/foo.txt
What would "abs" really be?
TIA,
Matthew