Vladimir Bezugliy Vladimir Bezugliy - 6 months ago 19
Bash Question

"/bin/sh 'ls -l -R'" vs "/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'

Answer

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.

Comments