What do these exec su parameters do?

What is the meaning of the switches and parameters of this command?

exec su -s /bin/sh -c 'exec "$0" "$@"' root -- /opt/nsq/bin/nsqd

Specifically the -- part and what exec "$0" "$@" is supposed to do.

I know $0 sets a loop for the script to keep running.

You can ignore the /opt/nsq/bin/nsqd part. This is the app I'm running.

0

1 Answer

exec

The command it runs, su, replaces the shell without creating a new process.

sudo -s /bin/sh -c 

The substitute user runs the specified shell, /bin/sh and executes the following command.

exec "$0" "$@"

Run command $0 , the name of the script, (your first variable, i.e., /opt/nsq/bin/nsqd )

"$@"

with all the arguments, using the appropriate quoting

--

The double hyphens delimit the option list. Everything following, even if they begin with a hypen, are considered to be operands. For example, sort -- -r reads from the file named -r instead of trying to use '-r' as an option.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like