Take this script, merely as an example
#!/bin/sh
foo ()
{
eval "$@"
}
touch bar
foo tail -f bar &
sleep 1
kill $!
In this example I would like to kill tail, however because tail was invoked as the result of an eval, it does not get killed. How could I kill tail without resorting to pgrep, pkill, etc?
Using
execinstead should workIf using with a pipe, you will need to do process substitution
related