【发布时间】:2011-09-27 11:12:23
【问题描述】:
我有一个非常简短的 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
对这里的奥秘有什么合乎逻辑的解释吗?非常感谢!
【问题讨论】:
-
当我运行你的脚本时,输出的最后一行是:
The current directory is /home/user/asdf所以我不知道。我猜你的环境中的某些东西可能会扭曲结果。 -
我使用的是 Ubuntu 9.10。似乎在输出“ls -l”,但由于“pwd”在 shell 下工作正常……很奇怪
-
可能是您的 perl 使用另一个 shell 进行 `` 调用,而不是您用于比较的,因此有其他设置?
printtype pwd;在 perl 中打印什么? (里面有反引号)? -
在Ubuntu中,脚本执行的默认shell是
dash,而用户交互的默认shell是bash。我想 Perl 会调用第一个,并且您在破折号初始化脚本中定义了一些别名。 -
@Paŭlo Ebermann,Perl 在需要 shell 时使用
/bin/sh,尽管在这种情况下它根本不使用 shell。
标签: linux perl unix ubuntu pwd