I have some bash aliases in my ~/.bashrc, but they're not available within a watch command. Normally, I would source ./some_script.sh which uses these aliases, but am having trouble figuring out how to do that with the watch command.

$ watch "my-alias"
Every 2.0s: my-alias

sh: 1: my-alias: not found
watch -x bash -c "my-alias"
Every 2.0s: my-alias

sh: 1: my-alias: not found

aliases are enabled in interactive shells, so try this:

watch -x bash -ic "my-alias"
# .............^
  • 2
    That's it! An extra option on bash, not watch. I found I had to add an additional bit to make sure the interactive shell didn't exit with an error. So my working usage is watch --interval 10 --exec /bin/bash -ic "my-alias || true" – tarabyte Oct 15 '20 at 18:29
  • in case of zsh: watch -x zsh -ic "my-alias" – Junaid Jun 15 at 22:01

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.