What is /bin/sh -c?

LinuxSh

Linux Problem Overview


What does /bin/sh -c mean? What does -c do?

Linux Solutions


Solution 1 - Linux

From the man-page of bash:

> -c string > > If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.

Example:

$ bash -c ls

will launch bash and execute the command ls.

/bin/sh is usually a symlink to a shell.

Solution 2 - Linux

With -c (command) it returns to the first shell instead of let open a new one.
It is very similar to: sudo su -l -c 'echo "run a command and return"'
Example:

#sudo su -l knoppix -c 'echo "run a command as ${USER} and return"'
run a command as knoppix and return
#

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser481831View Question on Stackoverflow
Solution 1 - LinuxaioobeView Answer on Stackoverflow
Solution 2 - LinuxkoyaanisqatsiView Answer on Stackoverflow