You are not logged in.

#1 2016-04-04 16:57:49

dewillepl
Member
Registered: 2016-02-12
Posts: 13

Bash - problem with finding file

Hi guys,

System can't find a file using command "find" when searched filename contains square bracket  [xyz] (can't find when close bracket exist)  ie. find /path -type f -size +1M -iname "*file.name.1.2.3-4ABC[xyz]*" I can find when "*file.name.1.2.3-4ABC[xyz*"

Does "find" command can handle that ?

Thanks

Offline

#2 2016-04-04 17:00:42

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,797

Re: Bash - problem with finding file

Escape the [ and ].  Enter them as \[ and \]


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2016-04-04 17:20:52

dewillepl
Member
Registered: 2016-02-12
Posts: 13

Re: Bash - problem with finding file

apologies, i forgot to mention my searched filename is variable $filename (result of other function) and because of that i can't modify this string

Offline

#4 2016-04-04 17:39:59

EmilyShepherd
Member
From: Bucks, UK
Registered: 2016-03-20
Posts: 45
Website

Re: Bash - problem with finding file

dewillepl wrote:

apologies, i forgot to mention my searched filename is variable $filename (result of other function) and because of that i can't modify this string

It is possible to modify variables in Bash:

filename=${filename/[/\\[}
filename=${filename/]/\\]}

Offline

#5 2016-04-05 09:39:00

dewillepl
Member
Registered: 2016-02-12
Posts: 13

Re: Bash - problem with finding file

It's not working unfortunately, but i fixed my issue by using sed when generating variables.

Thanks

Offline

#6 2016-04-05 17:38:42

Steef435
Member
Registered: 2013-08-29
Posts: 577
Website

Re: Bash - problem with finding file

Can't you just put quotes around the variable? E.g. "$filename" instead of $filename.

Offline

Board footer

Powered by FluxBB