与 GNU coreutils 命令等效的 Perl 命令是什么 readlink -f
?
If any component of the file name except the last one is missing or unavailable, readlink produces no output and exits with a nonzero exit code. A trailing slash is ignored.
最佳答案
您可以使用 Cwd :
use Cwd 'abs_path';
my $path = "/some/arbitrary/path";
print abs_path($path);
测试:
for q in exists imaginary imarginary/imaginary ; do
echo "$q"
echo -n "readlink -f: " ; readlink -f "$q"
echo -n "abs_path: " ; perl -MCwd=abs_path -E'say abs_path $ARGV[0]' "$q"
echo
done
输出:
exists
readlink -f: /home/eric/exists
abs_path: /home/eric/exists
imaginary
readlink -f: /home/eric/imaginary
abs_path: /home/eric/imaginary
imaginary/imaginary
readlink -f: abs_path:
关于与 readlink 行为相同的 Perl 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19001957/