lonestar21
lonestar21

Reputation: 1183

bash script variable passing to find

I have a simple bash script where I generate some temporary files using split, do some processing and then try to track down all the files at the end and merge them

rand_int=$RANDOM
split -d -l $n_lines_split $1 $rand_int   #works fine

for f in $(find . -amin -200 -regex '.*$rand_int.*' ); do 
    (some processing here) ; 
done

My problem is that in the find command $rand_int is interpreted literally, whereas I want to use the variable's value.

Upvotes: 6

Views: 4808

Answers (2)

Dan Fego
Dan Fego

Reputation: 13994

In the shell, single-quotes (') cause what's inside to be interpreted literally. What you want to do is use double-quotes (") around the expression with $rand_int.

So for the find expression:

find . -amin -200 -regex ".*$rand_int.*"

Upvotes: 6

user237419
user237419

Reputation: 9064

use " " instead of ''

for f in $(find . -amin -200 -regex ".*$rand_int.*" ); do 

Upvotes: 2

Related Questions