3

I have certain PDF files. I want to inspect each of them for 20 seconds. The way I was trying to do that is like following: for file in *.pdf; do echo $file; evince $file; sleep 20s; killall evince; done . It displays the first file, but does not kill it after 20s. What is going wrong here?

Rmano
  • 32,167
rivu
  • 636

2 Answers2

2

Note that you don't have to kill all: you can kill the specific instance:

for file in *.pdf; do
    echo "$file"
    evince "$file" &
    sleep 20s
    kill $!           
done

$! is the pid of the most recently backgrounded process. (http://www.gnu.org/software/bash/manual/bashref.html#Special-Parameters)

glenn jackman
  • 18,218
1

I think you just forgot to run evince in background:

for file in *.pdf; do echo $file; evince $file &; sleep 20s; killall evince; done

Notice the & after the evince command.

Rmano
  • 32,167