3

I have a script:

ACTION="build"

env -i
exec ./makelib.sh Release "${ACTION}"

env -i
exec ./makelib.sh Debug "${ACTION}"

Second exec does not execute. Why, and how can I execute it?

3 Answers 3

3

exec will replace the entire process with the contents of the command you're passing in--in this case, makelib.sh. Check out the man page for the linux exec function--it explains it in depth.

I assume this is a shell script; if you want the script to simply RUN the other scripts sequentially (one after the other), you'll use:

ACTION="build"

env -i
./makelib.sh Release "${ACTION}"
./makelib.sh Debug "${ACTION}"

This will run ./makelib.sh Release "${ACTION}" first; after it finishes, it will run ./makelib.sh Debug "${ACTION}". If you want both commands to run in parallel (at the same time), you can background the process using &.

ACTION="build"

env -i
./makelib.sh Release "${ACTION}" &
./makelib.sh Debug "${ACTION}" &

Keep in mind that background both processes means you'll have two processes running (and outputting!) simultaneously. So if you have logging output, your screen will get messy, to say the least.

Hope this helps!

2
  • Wow! in parallel! Awesome! Thanks! And additionally, does parallel execution work on all kind of shells? Or specific kind of shells?
    – Eonil
    Sep 1, 2010 at 15:31
  • Just about any modern shell you would use will support it; bash, zsh, ksh, etc.. Check out the bash manual topic on job control for some useful tips on using your shell to its fullest! gnu.org/software/bash/manual/bashref.html#Job-Control
    – Andrew M.
    Sep 2, 2010 at 3:05
2

exec is substituting the current shell by the commands passed. If you want the script to continue, remove the exec statement(s).

3
  • Is there a way to executing external script without substitution?
    – Eonil
    Sep 1, 2010 at 14:52
  • Wow. I understand. I removed exec characters, then it worked. Thanks!
    – Eonil
    Sep 1, 2010 at 14:58
  • See my answer for an explanation of why it works. :)
    – Andrew M.
    Sep 1, 2010 at 14:59
0

What about adding the "&" character to the end of the line if you want it to run in the background, or "&&" between the first and second statements if you want the second to be conditional on the first being successful?

(My shell-fu is weak, so I'd love to hear why this may be wrong, for educational purposes.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .