Skip to content

Instantly share code, notes, and snippets.



Last active Feb 15, 2018
What would you like to do?
#!/usr/bin/env bash
set -eo pipefail
_stopnow() {
test -f stopnow && \
echo "Stopping after $count iterations!" && \
rm stopnow && exit 0 || return 0
# run if user hits control-c
echo "Managed to do $count iterations"
exit $?
# trap keyboard interrupt (control-c)
trap control_c SIGINT
echo "To stop this forever loop created a file called stopnow."
echo "E.g: touch stopnow"
echo ""
echo "Now going to run '$@' forever"
echo ""
while true
eval $@
# Do this in case you accidentally pass an argument
# that finishes too quickly.
sleep 1

This comment has been minimized.

Copy link

@lamby lamby commented Feb 13, 2018

This should be:


.. by itself on a newline (without the eval) otherwise you expand spaces. Try, for example, running ls "foo bar" in a loop. With a raw eval $@ you would see "cannot open foo, cannot open bar` which is incorrect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.