I have seen wrapper script examples which in a nutshell are following:
#!/bin/bash
myprog=sleep
echo "This is the wrapper script, it will exec "$myprog""
exec "$myprog" "$@"
As seen above, they use exec
to replace the newly created shell almost immediately with the $myprog
. One could achieve the same without exec
:
#!/bin/bash
myprog=sleep
echo "This is the wrapper script, it will exec "$myprog""
"$myprog" "$@"
In this last example, a new bash instance is started and then $myprog
is started as a child process of the bash instance.
What are the benefits of the first approach?
exec
builtin. – Scott - Слава Україні Apr 26 '16 at 05:19