Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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!

share|improve this answer
    
Wow! in parallel! Awesome! Thanks! And additionally, does parallel execution work on all kind of shells? Or specific kind of shells? –  Eonil Sep 1 '10 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 '10 at 3:05

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

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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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