blueberryfields
blueberryfields

Reputation: 50448

How do I check if a string is included in the results for a bash command?

In a bash script, I have a line approximately like so - which returns a multi-line response:

FILE_LIST = $(find some/path -type f )

I'd like to check whether the response contains a particular string, for example:

IF  not ("filename" in FILE_LIST)

How do I perform this kind of test inside a bash script?

Upvotes: 0

Views: 58

Answers (1)

Leonid Volnitsky
Leonid Volnitsky

Reputation: 9144

if echo "$FILE_LIST" |tr ' ' '\n' |grep -q "filename"

Or directly:

if find some/path -type f | grep -q "filename" 

Your FILE_LIST won't work for files with spaces though.

Upvotes: 3

Related Questions