I'm a green hand in Shell. Please see my following code. How to make it working?
[root@localhost ~]# ls {*.txt,*.exe}
a.txt b.txt a.exe b.exe
[root@localhost ~]# filter={*.txt,*.exe}
[root@localhost ~]# echo $filter
{*.txt,*.exe}
[root@localhost ~]# ls $filter
ls: {*.txt,*.exe}: No such file or directory
[root@localhost ~]#
This should do the trick:
eval ls $filter
NOTE: Assuming Bash and Linux here in absence of any concrete information.
First of all you can get this via find, e.g.
find -type f -name '*.sql'
... or echo:
echo *.{sql,log}
as well. Many ways to do one thing in *nix shells :)
Secondly you'd have to eval the expression to make use of the globbing feature (globbing is the technical term for wildcard expansion).
You'll also want to enclose the assignment in single quotes to avoid expansion to happen too early:
filter='*.{sql,log}'
then observe:
$ echo $filter
*.{sql,log}
but:
$ eval "echo $filter"
test.sql test.log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With