This one has been bugging me for a while: I want to use the marvelous GNU watch command to run a few custom aliases and functions that are defined in my .bashrc, but it is never able to run anything except bash built-ins or binaries.

watch -d foo

The output is always: foo: command not found

How can I make it inherit my environment or use the .bashrc?

Thank you.

  • What is foo? A shell script? An alias? What if you run that watch command from your prompt?
    – lorenzog
    Mar 17, 2010 at 23:18
  • As I mentioned, foo can be a custom alias or a bash function, not just a simple call to a binary. Mar 17, 2010 at 23:34
  • Here's an example of a bash function: x () { xmllint -format $* ;} Mar 17, 2010 at 23:35

2 Answers 2


Do something like this watch bash -i -c 'alias -p' this should call bash, load your settings and then run whatever command you have after the -c

  • Brilliant - that worked like a charm. Mar 18, 2010 at 5:19
  • Great! But my functions are still not visible :( ....when is used after pipe (|)
    – sobi3ch
    Feb 23, 2018 at 9:07

From man watch:

Note that command is given to "sh -c"

So it's not going to see your Bash aliases and functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.