フルパスをマージ/計算するためのネイティブ関数 (シェル、Linux コマンド) はありますか?
例:
old_path="~/test1/test2/../dir3//file.txt"
new_path=FUN($old_path)
echo "$new_path" // I want get this "/home/user/test1/dir3/file.txt"
する
new_path=$(eval cd "$old_path"; pwd)
あなたのために働きますか?pwd -P
シンボリックリンクを解決したい場合にも使用できます。in$HOME
の代わりに使用すると、生活が楽になります。その後、必要はありません。~
old_path
eval
使用readlink
:
$ readlink -m ~/foo.txt
/home/user/foo.txt
$ readlink -m ~/somedir/..foo.txt
/home/user/foo.txt
また、シンボリックリンクも処理します。