我不知道这些路径是否重复。给定相对路径,我如何使用shell脚本确定绝对路径?
例:
relative path: /x/y/../../a/b/z/../c/d absolute path: /a/b/c/d
解决方法
从
this source来:
#!/bin/bash # Assume parameter passed in is a relative path to a directory. # For brevity,we won't do argument type or length checking. ABS_PATH=`cd "$1"; pwd` # double quotes for paths that contain spaces etc... echo "Absolute path: $ABS_PATH"
你也可以做一个Perl单行,例如。使用Cwd::abs_path