For example, the current directory has 2 files: 1x and 2x. I use the following bash script to find them. But I get nothing:
#!/bin/bash
var=x
pattern=`printf "'%s'" "*${var}"`
echo $pattern
find -name $pattern
I can put eval before find to get the above script work. Why eval is need here? And is there a way to do it without using eval?
You don’t need to single-quote it, you only need to inhibit expansion.