Replace [ ] by [[ ]] in multiple subdirs

Dear guru's

I have a bunch of scripts that were written in bash and are now supposed to become sh compatible regarding the conditions( [ condition ] && .. and if [ condition ];then ..
Within those scripts there are obviusly some math operations like var=$[ 1 + 2 ] or array usage like var=${array[1]}

Now these scripts are also spread among folders, tree said its 57 directories, 295 files...
So each entry there is a script/plaintext, unless its a folder.

Now i'd go for something like:

#!/bin/sh
cd /path/to/dir

list_full=""
list_todo=""

list_full=$(find $(pwd)/|grep -v .git/|grep -v .desktop|grep -v .ks$|grep -v .spec$)
for found in $list_full
do
	[[ -f "$found" ]] && \
		[[ ! "" = "$(grep \\\[ $found)" ]] && \
		list_todo+=" $found"
done

for task in $list_todo
do
	this="$(basename $task)"
	printf "\nParsing: $this:"

	grep \\\[ $task
	# here the issue starts
	# about/with the diffrent '['' occourences
done

printf "\n"
echo "$list_todo"|wc

Returns:

Parsing: release.conf                                 
      1     180   12985

But i feel very unsafe with sed ing within that for each.
Specialy since [ requires to be escaped..

Now i'd like to ask for help 'getting' those (shell escaped regex/posix??), or if you would know a better method.
Thank you in advance

EDIT: Sysinfo

uname -ro
3.11.6-200.fc19.x86_64 GNU/Linux

EDIT:
Weird, after adding some removals at list creation, the (end)list got reducded from 180 to 167, at least that value of wc changed.
BUT:

find |grep spec$
./menu/dev/rpm/spec
./templates/dev/sourceforge.spec
./templates/dev/empty.spec
./templates/dev/github.spec

But by now, i cant get 180 again - it jumps from 177 to ~432 (git)
:confused:

Backup everything first!

First I'd focus on making sure you have a proper list of the script files to be changed as you have a lot of non-scripts files in that tree (eg .rpm repositories menu data files and the like).

Perhaps find file that have the executable bit set and the file command reports as "shell script" or "ASCII text". You could very well find that only 30 or 40 of these 295 files are actually shell scripts.

Once you get replacement code produce the new scripts in another folder and then use diff to vet what it's doing. Look over it carefully looking any exceptions/incorrect replacements.

As the tree output seems to confuse more than to help, it got deleted.

Chubler_XL Thank you for your 'exact view' for the rpm extension. (sorry dont know better words;lost in translation)
But its just a script containing functions regarding the handling/creation of rpm files.
Same goes for the menu, its all script (plaintext/ASCII) files.

As the script returns:

echo "$list_todo"|wc                              
      1     167   11976

I figure there are 167 files containing [.
Given the assumption that grep \\\[ is the proper syntax.

Besides, i had redirected the scripts output to a file, which was 90k (of which ~6k were the path-file names).
The tarball of all scripts is ~150k.

As grep \\\[ $task seems to work for a rough overview,
how could i exlude math and array stuff?

Any direct sed access, without grep pre-definition of a variable, is beyond my current understanding.

Yes, but problem you are likely to have is that "[" is also used a lot in programs called by the scripts (eg sed, awk and grep) eg:

if [[ "$MENU" == *1* ]]
then
     echo $LINE | sed 's/[[:space:]]*/ /g'
fi

You would probably want to change the if statement in the above but not the sed code.

Yes and no.
I would like to have it become:

if [[ "$MENU" == *1* ]]
then
     echo $LINE | sed 's/[[:space:]]*/ /g'
fi

from

if [ "$MENU" == *1* ]
then
     echo $LINE | sed 's/[[:space:]]*/ /g'
fi

Also those [[:space:]] are already double brackets, so should not be touched anyway...
Some REGEX i dont want to mess either, but then, those are usualy close [aA] , unlike conditions [ condition ] .

I'm aware of the trouble, thats why i ask here for help.
Its a 1 person project, and changing 167 files is pita to do manualy...

Tell me what you need to know, i'd happily share it.
So the attachment contains a the lines "Parsing: FileXY" and the according grep \\\[ output of that file, so you could get the an overview..
(1800 lines ; 167 of which refering to the file containg the code following)

I assume not all shell scripts having the shebang #![ba]sh ?
Why don't you use a more specific regex, e.g. grep -Er "(if *\[ +)|( +] +(\&\&|\|\|))" to look for testing conditions?
And, you could simplify that find pipe: find . ! \( -iname \*.git -o -iname \*.spec -o -iname \*.desktop \)