Artificial intelligent assistant

Use file marker with entr I've the following code on `myscript.sh` for the purpose of execute function on a file with `.md` extension when this file is modified: function my_function(){ echo "I\'ve just seen $1" } typeset -fx my_function find . -name "*.md" | entr -r -s "my_function $0" entr documentation: * [...] the name of the first file to trigger an event can be read from $0.* I expect when I change README.md that output will be: "I've just seen README.md" In reality when i launch the script and change README.md, following output appears: bash myscript.sh # output: I've just seen myscript.sh Please, why ?

You are calling entr from a shell script. When the shell performs variable substitution (or parameter expansion in the manual), `$0` will expand to the filename of the script. To protect the `$0` from variable substitution by the shell, use `\`:


find . -name "*.md" | entr -r -s "my_function \$0"


**Edit:** As @roaima reminded, another way is to use single quotes, which protects the entire quoted text:


find . -name "*.md" | entr -r -s 'my_function $0'


**NB:** If the `SHELL` environment variable is set to something incompatible with bash, `typeset -fx my_function` might not work at all for entr (for example, it doesn't work with `SHELL=/bin/mksh`). Also, consider adding a shebang) to your script, and leaving out the unnecessary word `function`:


#!/bin/bash
my_function(){
echo "I've just seen $1"
}
typeset -fx my_function

find . -name "*.md" |
entr -r -s "my_function \$0"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy b211ab85cd286c6e3e4462db3501d677