0

Motivated by How can I change my command to run without superuser privilleges but with the changed limit value?, in a bash shell, if I run

exec su $LOGNAME && sleep 100

will the sleep command ever be executed?

I think not, because exec su $LOGNAME will replace the shell in the current process with another shell. When I exit the new shell normally (for &&), the process terminates and there is no process to execute the sleep command.

Thanks.

1

It shouldn't. Either the exec succeeds, and the shell is replaced, or the exec fails in which case && doesn't run the following command. exec somcmd || echo fail or exec 2>somefile && echo ok would be different, though.

0

No it will not, check:

ksh93
$ exec /bin/echo bla && sleep 1 && echo foo
bla

You will get back to the previous shell and the exec replaces the ksh93 instance completely.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.