在 AIX 上运行时,以下两个命令有什么区别?
/bin/sh 'ls -l -R'
/bin/sh -c 'ls -l -R'
在 AIX 上,/bin/sh
默认为 Korn Shell (ksh)。
/bin/sh 'ls -l -R'
使用 ksh,这会运行 shell,告诉它执行名为ls -l -R
(在当前目录或路径上)的脚本。如果找不到具有此名称的脚本,则 ksh 将参数视为命令并运行它。
请注意,使用 bash,如果找不到脚本,则会导致错误。
/bin/sh -c 'ls -l -R'
这将启动一个新的 shell 实例,告诉它运行 command ls -l -R
。
(这是对菲尔罗斯的回应,但我需要格式化:)
使用我的一个 Linux 帐户:
sh> /bin/sh --version
GNU bash, version 3.2.39(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
sh> /bin/sh 'ls -l -R'
/bin/sh: ls -l -R: No such file or directory
sh> /bin/sh ls
/bin/ls: /bin/ls: cannot execute binary file
sh> /bin/sh -c 'ls -l | head -1'
total 147296
sh>
使用我的 Cygwin 安装之一:
sh> /bin/sh --version
GNU bash, version 3.2.49(23)-release (i686-pc-cygwin)
Copyright (C) 2007 Free Software Foundation, Inc.
sh> /bin/sh 'ls -l -R'
/bin/sh: ls -l -R: No such file or directory
sh> /bin/sh ls
/usr/bin/ls: /usr/bin/ls: cannot execute binary file
sh> /bin/sh -c 'ls -l | head -1'
total 264744
sh>
您/bin/sh
可能会有所不同,但这似乎是适当的行为:
有关更多详细信息,请键入
man sh