1

I'm trying to monitor some files with entr.

My script based on their examples:

do_it(){ echo Eita!; }
while true; do ls folder/* more-folder/* | entr -pd do_it; done
>> entr: exec do_it: No such file or directory

However, this works:

while true; do ls folder1/* folder2/* | entr -pd echo Eita!; done

What am I doing wrong?

1

2 Answers 2

2

The pipeline in your "while" loop runs in separate subshells. Since the do_it function is not exported, the child subshell on the right that runs entr does not know about it. The shortest solution would be to export the function (bash allows this).

do_it(){ echo Eita!; }
export -f do_it
while true; do ls folder/* more-folder/* | entr -pd do_it; done

If the entr command wants to execute something from disk, then I would suggest putting the function in a script file, then point entr to that.

file named /path/to/do_it

#!/bin/sh
echo Eita!

ensure the file is executable:

chmod +x /path/to/do_it

new commandline:

while true; do ls folder/* more-folder/* | entr -pd /path/to/do_it; done
5
  • Not working here... "entr: exec do_it: No such file or directory"
    – Roger
    Aug 28, 2019 at 19:34
  • Some light? See: superuser.com/a/396652/88723
    – Roger
    Aug 28, 2019 at 19:48
  • Apparently entr wants to find an executable in your path, and is unsatisfied with a bash function. I'll update my answer with something else to try.
    – Jeff Schaller
    Aug 28, 2019 at 20:19
  • Yes, it works. But the big question is: why with a function it is returning "entr: exec do_it: No such file or directory"? Everything I read points to the fact entr is using "exec".
    – Roger
    Aug 28, 2019 at 20:52
  • By the programmers of entr: github.com/eradman/entr/issues/6
    – Roger
    Aug 29, 2019 at 13:52
0

Answered by the programmers of entr (https://github.com/eradman/entr/issues/6): "A function can be exported to a subshell, but you cannot execute a function with an external program. If you want to execute shell functions, you can write a loop such as this:"

do_it(){ echo 'Eita!'; }

while true; do
    ls folder1/* folder2/* | entr -pd -s 'kill $PPID'
    do_it
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .