Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The problem is that when watch is executed it runs sh and I get this error:

sh: 1: func1: not found

here is the code:


  echo $1

export -f func1

watch func1
share|improve this question
Can you give what command you actually run? – cuonglm Jul 13 '14 at 18:38
@Gnouc instead of echo $1 i have a bit long script so i don't know .. – Rachid Oussanaa Jul 13 '14 at 18:42
I mean how did you run your ssh command? – cuonglm Jul 13 '14 at 18:45
@Gnouc ./bin/myfunc.sh – Rachid Oussanaa Jul 13 '14 at 19:00
up vote 4 down vote accepted

Ok, so there are a few issues with your approach.

You are exporting a function, which is not portable between shells. watch executes its commands with /bin/sh, which on your system is not bash. And whatever shell it is, it doesn't respect function exports, so you get the error.

Secondly, you can change your command to something like watch bash -c 'func1', but this may not work well either.
The reason here being that any variables set by the script won't be available to the function. You might be able to export the ones it needs, but that starts getting messy.

The safest solution is to put func1 in a script by itself and call that script.

In short, try:

watch bash -c func1
share|improve this answer
It is very CPU intensive in case function is defined in .bash_profile – VarunAgw Feb 1 at 16:59

Why run watch from inside your script? Why not have this shell script:

$ cat func1 

  echo $1

func1 $1

... and then run it like so ...

$ watch func1 foo
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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