6

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.

2 Answers 2

6

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.*"
Sign up to request clarification or add additional context in comments.

1 Comment

beautiful! Funny, I used to use Perl (same convention), and that hadn't even occurred to me
2

use " " instead of ''

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.