Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is /bin/sh -c?

Tags:

linux

sh

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

like image 514
user481831 Avatar asked Oct 21 '10 07:10

user481831


People also ask

What is bin sh used for?

#!/bin/sh: It is used to execute the file using sh, which is a Bourne shell, or a compatible shell. #!/bin/csh: It is used to execute the file using csh, the C shell, or a compatible shell.

What is bin bash and bin sh?

Basically bash is sh, with more features and better syntax. Most commands work the same, but they are different. Bash (bash) is one of many available (yet the most commonly used) Unix shells. Bash stands for "Bourne Again SHell",and is a replacement/improvement of the original Bourne shell (sh).

What is bin sh file?

/bin/sh is an executable representing the system shell and usually implemented as a symbolic link pointing to the executable for whichever shell is the system shell. The system shell is basically the default shell that the script should use.

Is Bin sh necessary?

You don't need to and you shouldn't unless you have no choice. Use '#!/bin/sh' while you can and learn about the difference between a (POSIX) shell and bash.


2 Answers

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.

like image 124
aioobe Avatar answered Oct 08 '22 20:10

aioobe


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
#
like image 42
koyaanisqatsi Avatar answered Oct 08 '22 21:10

koyaanisqatsi