Quantcast
Channel: How to obtain the absolute path of a file via Shell (BASH/ZSH/SH)? - Stack Overflow
Viewing all articles
Browse latest Browse all 46

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

$
0
0
#! /bin/bashfile="$@"realpath "$file" 2>/dev/null || eval realpath $(echo $file | sed 's/ /\\ /g')

This makes up for the shortcomings of realpath, store it in a shell script fullpath. You can now call:

$ cd && touch a\ a && rm A 2>/dev/null $ fullpath "a a"/home/user/a a$ fullpath ~/a\ a/home/user/a a$ fullpath AA: No such file or directory.

Viewing all articles
Browse latest Browse all 46

Trending Articles



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