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.

2 Answers 2

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.

1
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.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.