Problem with recursion in subdirectories

Hello !
I need some help with my simple bash script.
This script removes all files ( with name given in $1 ) in current dir and subdirectories .
The problem is with first loop in the script ( for file in * ; do ) .
When I run the sript in my home directory this script display sometimes(
probably special directories ) strange massage like :
" [: 31 : (d.) .png : undexpected operator " .
But When I write this loop like this : " for file in $( ls $dir ) " the sript
working perfectly ( but slow) .
How to remove the strange message ?

Pawe epko

Welcome to the forum! :slight_smile: :slight_smile: :slight_smile:

To remove strange errors as you had mentioned
the script could be run as,

./script.sh 2>/dev/null

Well, that is not advisable,
could you please run the script with debug mode

set -x

to see why these errors do really occur !!!
( probably seems like missing parameters to test )

If the errors are fixed, then there is no need to run it as 2>/dev/null

:slight_smile:

I run the script in debug mode ( set -x ) and i found the problem - the problem is
probably with "=" operator .

When I try to remove file photo.png

In debug moge I get message like this:
...
+ [ Expirience ubuntu.ogg = photo.png ]
[ : 1 : ubuntu.ogg : Undexpected operator ]
..

I don't know how to remove this problem ?

[ Expirience ubuntu.ogg = photo.png ] 

Expirience ubuntu.ogg is a single filename with space in between. Use quotes to avoid this problem

if [ "$file" = "$2" ] && [ -f "$file" ] ; then # 

Thanks for help!

Pawe epko