Unix command find doesn’t do what I want to do.
Here is the situation
If I type:
find ../tmp -name "\*tmp\*"
it correctly outputs the files that contain “tmp” in its name in tmp folder
but when I type:
dir=../tmp #assign ../tmp as a variable named dir
find ${dir} -name "\*tmp\*"
the output says: No such file or directory
My guess is that the find command assumes that the variable “dir” as a file to look for?
How can I go around this problem?
The reason I want to know this is so that I can pass the path as an argument for my script.
Thanks
———–Additional comment
I use the bash shell.
Sorry for the confusion. The above code works. The real problem is when I incorporate {} structure in the variable. For example,
When I type
dir=../{tmp1,tmp3} #assign ../{tmp1,tmp3} as a variable named dir
find ${dir} -name “*tmp*”
the output says: No such file or directory
Why??
The command line is evaluated command-wise first and then any action (like setting environment variables, calling programms) is done. Therefore $dir is set not before the command line is evaluated. One possibility to solve the problem is to separate the variable setting from its usage by
;or to write the commands into two separate lines (Thiruvalluvar’s answer).