What is the difference between the following two commands, when run on AIX?
/bin/sh 'ls -l -R'
/bin/sh -c 'ls -l -R'
What is the difference between the following two commands, when run on AIX?
/bin/sh 'ls -l -R'
/bin/sh -c 'ls -l -R'
On AIX, /bin/sh
defaults to the Korn Shell (ksh).
/bin/sh 'ls -l -R'
With ksh, this runs the shell, telling it to execute the script named ls -l -R
(in the current directory or on the path). If no script can be found with this name, ksh treats the argument as a command and runs it.
Note that with bash, if the script cannot be found, this would result in an error.
/bin/sh -c 'ls -l -R'
This starts a new instance of the shell, telling it to run the command ls -l -R
.
(This is in response to Phil Ross, but I need formatting:)
Using one of my Linux accounts:
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>
Using one of my Cygwin installations:
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>
Your sh may vary, but this appears to be the appropriate behaviour:
For more details, type
man sh