5

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.

3
  • What is foo? A shell script? An alias? What if you run that watch command from your prompt?
    – lorenzog
    Mar 17 '10 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 '10 at 23:34
  • Here's an example of a bash function: x () { xmllint -format $* ;} Mar 17 '10 at 23:35
7

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

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

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.