Reputation: 1743
I have the following in my bash file: (I would like to kill a web server once the bash script is over under any circumstances)
python -m SimpleHTTPServer 12345 &
trap "kill $!" EXIT
I am wondering how safe/widespread is this? When will $!
actually be evaluated (I am pretty sure that this happens at the place of declaration, but still need advice)?
Upvotes: 0
Views: 94
Reputation: 361605
What you wrote is safe. Because you're using double quotes, $!
is evaluated immediately. If you used single quotes it would be evaluated at the time the script exits.
Upvotes: 5