What does /bin/sh -c
mean? What does -c
do?
From the man-page of bash:
-c string
If the
-c
option is present, then commands are read fromstring
. 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.
bash myScript
but it will open myScript
and interpret the commands. This is not the same as bash -c someCommand
. Compare what happens if you do bash ls
and bash -c ls
for instance. –
Sealey bash script.sh
or bash -c 'ls -la'
. -c
parameter is the command with its parameters, that will be passed to the bash
command interpreter. If your standard command interpreter is bash
, then ls -la
and bash -c 'ls -la'
are equivalent –
Shane 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
#
/bin/sh
. –
Wynn Let's break it down.
/bin/sh
: This launches a Bourne shell, a basic command-line interpreter that is available on most Unix-like operating systems.
-c
: This option tells the shell to read the command from the following string. It allows you to specify a command inline, without the need to write a separate script file. This option works in both sh
and bash
.
For example, if you run:
/bin/sh -c "echo Hello, World!"
This command tells sh
to execute the echo Hello, World!
string.
© 2022 - 2024 — McMap. All rights reserved.
-c
? – Algophobia