我有一个非常简短的教程 perl 脚本:
#!/usr/bin/perl
print "The date is ",`date`;
print "The date is `date`",".\n";
$directory=`pwd`;
print "\nThe current directory is $directory.";
和输出:
The date is Sat Jul 2 17:04:58 PDT 2011
The date is `date`.
The current directory is total 20
-rwxr-xr-x 1 yan yan 433 2011-07-02 15:58 36
-rwxr-xr-x 1 yan yan 313 2011-07-02 16:29 43
-rwxr-xr-x 1 yan yan 116 2011-07-02 16:51 45
-rwxr-xr-x 1 yan yan 149 2011-07-02 16:53 46
-rwxr-xr-x 1 yan yan 145 2011-07-02 17:02 47
但是如果我只运行 pwd 我会得到:
yan@ubuntu:~/bin/blackperl$ pwd
/home/yan/bin/blackperl
对这里的谜团有什么合乎逻辑的解释吗?非常感谢!
最佳答案
我也无法解释这个谜团,但你可以尝试使用 Perl Core 模块 Cwd而不是 pwd
命令:
use warnings;
use strict;
use Cwd;
my $dir = getcwd();
print "$dir\n";
一个优点是 Cwd
比 pwd
更便携。
关于linux - perl 输出奇怪的 `pwd`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6560301/