gpt4 book ai didi

与 readlink 行为相同的 Perl 命令?

转载 作者:行者123 更新时间:2023-12-05 08:58:58 26 4
gpt4 key购买 nike

与 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com