Jeegar Patel Jeegar Patel - 3 months ago 9x
Bash Question

Run while loop until background process finish its job

In linux shell script i have

vlc /some/file/path.mkv &

Now until my background process return
call will be blocked. But here i want that until my background process return i want to execute one loop and in that print some data continuous. So when ever my background process return/exit i need to break that loop.

How to do that in shell script?


See if this works for you

vlc /some/file/path.mkv &
while [[ -n $(jobs -r) ]]; do echo -n "some data"; sleep 1; done

jobs -r checks running processes, and printing something, the script stops when your vlc process is done.