expand wildcards in string variable

Viewed 3116

I'm reading strings from a blacklist file which contains files and folders which should get deleted. It works for simple file names, but not with wildcards.

E.g. if I type on the shell rm -rf !(abc|def) it deletes all but these two files. When putting this string !(abc|def) into blacklist it does not work, because the string does not get evaluated.

So I tried to use eval, but it does not work as expected.

#!/bin/bash
# test pattern (normally read from blacklist file)
LINE="!(abc|def)"

# output string
echo "$LINE"

# try to expand this wildcards
eval "ls $LINE"

# try with subshell
( ls $LINE )

How can I make this working?

1 Answers
Related