Artificial intelligent assistant

Excluding Bash File from modifying itself I'm learning how to make script "fool-proof". I have some scripts that modify files in the current folder but they also modify the script itself. I know it all boils down to the "for" loop with "find" I can't get right. for f in $(find . -type f | grep -v $0) My goal is to include all files it can find from the current catalogue and it's sub-catalogues but exclude the executed script itself. It's working with grep -v but now it's excluding every file that includes the name of the script (like copies of the script in the subfolders). Anyone knows how to make it work only for the executed script? I must assume someone might change the name at some point, so excluding it by hand is out of the question.

Example of the `find . -type f ! -path $0` approach. Note how the script only reports the `foo.sh` within the **"d"** directory. Not the `foo.sh` in the current directory.


$ find . -print
.
./a
./b
./c
./foo.sh
./d
./d/foo.sh
$ cat foo.sh
#!/bin/bash
for f in $(find . -type f ! -path $0); do
echo $f
done
$ ./foo.sh
./a
./b
./c
./d/foo.sh
$


Alternatively, try `for f in $(find . -type f | grep -v "^\./foo\.sh$"); do`

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a9a13c573296e6d5aba9feaa6e379e86