LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   break while [...] loop when a program finishes (https://www.linuxquestions.org/questions/linux-newbie-8/break-while-%5B-%5D-loop-when-a-program-finishes-789791/)

throughthegreens 02-17-2010 02:48 PM

break while [...] loop when a program finishes
 
I would like to start a program, then start a while loop that stops when the started program finishes, in bash. I thought I could run
Code:

(program ; stat=1) &
    while [ $stat -eq 0 ]; ... done

in a bash script

acid_kewpie 02-17-2010 03:25 PM

Code:

myprogram &
MYPID=$!
while [ -f /proc/$MYPID ]
do
  ...
done


throughthegreens 02-17-2010 05:36 PM

thanks

Valery Reznic 02-18-2010 02:22 AM

Quote:

Originally Posted by acid_kewpie (Post 3867336)
Code:

myprogram &
MYPID=$!
while [ -f /proc/$MYPID ]
do
  ...
done


/proc/$MYPID is directory, so it should be '-d' instead of '-f'
Code:

while [ -d /proc/$MYPID ]
Another option is to use 'kill -0 $MYPID'

acid_kewpie 02-18-2010 04:01 AM

Duh, actually I was wondering if my logic was even worse as it's procfs not a real filesystem, so presumably -f would never work even on files in there.

Valery Reznic 02-18-2010 04:39 AM

Quote:

Originally Posted by acid_kewpie (Post 3867907)
Duh, actually I was wondering if my logic was even worse as it's procfs not a real filesystem, so presumably -f would never work even on files in there.

I tried and it's looks like -f and -d work as they should on procfs too.

throughthegreens 02-18-2010 11:12 AM

i used -e


All times are GMT -5. The time now is 06:57 PM.