You can use watch -x or –exec option to pass command to exec(2) instead of sh -c which reduces the need to use extra quoting to get the desired effect.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 |
## create a function and export myfun() { echo 'hello world'; } export -f myfun ## watch -x or --exec options myfun ## returns hello world watch myfun ## returns hello world watch --exec myfun ## returns error watch --exec bash -c "myfun" ## returns hello world pkill -f "myscript.sh" ## kill myscript.sh rm my* |