Quantcast
Viewing latest article 24
Browse Latest Browse All 46

Answer by smac89 for How to obtain the absolute path of a file via Shell (BASH/ZSH/SH)?

In zsh, yes there is.

Assuming your path is stored in a variable, you can use the :P modifier to get the absolute path of the file.

Example:

f='../example.txt'echo ${f:P}

The above will print the absolute path of ../example.txt.

You can alternatively use the :A modifier to further resolve symbolic links, but this depends on realpath being installed.

f='../example.txt'echo ${f:A}

See https://zsh.sourceforge.io/Doc/Release/Expansion.html#Modifiers


Viewing latest article 24
Browse Latest Browse All 46

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>