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.

link|improve this question

50% accept rate
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. – Artem Russakovskii Mar 17 '10 at 23:34
Here's an example of a bash function: x () { xmllint -format $* ;} – Artem Russakovskii Mar 17 '10 at 23:35
feedback

2 Answers

up vote 2 down vote accepted

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

link|improve this answer
Brilliant - that worked like a charm. – Artem Russakovskii Mar 18 '10 at 5:19
feedback

From man watch:

Note that command is given to "sh -c"

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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