There are many instances on SO where people have asked how best to absolutize a path in bash, but I haven't found any that deal with absolutizing non-yet-existent paths.
The cd $1 && pwd method does not work at all for non-existent paths.
The readlink -f $1 method will only work for one level of non-existence; that is, it will work for "~/sdkjf", but not for "~/sdkjf/qweuio"
Ideally, I would like a method that would expand the latter to /home/username/sdkjf/qweuio ... and would also do similar transforms for ./ and ../
Can you recommend a solution?
readlink -m $1
From the manpage:
-m, --canonicalize-missing
canonicalize by following every symlink in every component of the given
name recursively, without requirements on components existence
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