Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote this bash:


    eval "(a command) &"

    eval "(while kill -0 $pid1; do .... ; done) &"  #It creates file.txt after few seconds

    if [ -s /tmp/file.txt ]; then
             for line in $(cat /tmp/file.txt)

With logic of bash scripting: Is the values of pid1 and pid2 correct?

Is this script running correctly?

share|improve this question
up vote 1 down vote accepted

I do not think you need the `eval "(...) &" syntax. Simply do this instead:

cmd1 &

cmd2 &

But otherwise your approach looks OK to me.


$ more ex.bash 

sleep 10 &

sleep 10 &

echo "ID1: $pid1 --- ID2: $pid2"

Now when I run it:

$ ./ex.bash 
ID1: 27866 --- ID2: 27867

We can confirm this is correct:

$ pgrep -l sleep
27866 sleep
27867 sleep
share|improve this answer
Thank you very much, I used eval because my commands are long and quite complicated... – MLSC May 25 '14 at 13:01
So my while loop with the condition kill -0 $pid1 is correct, isn't it? – MLSC May 25 '14 at 13:02
@MortezaLSC - seems reasonable to me. – slm May 25 '14 at 13:24

Your Answer


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.