0

I'm a newbie in bash and I would like to pass as parameter to a python function all files in a directory that don't match a given pattern. sth. like:

$myscripts/myprog.py $myfiles/!(bonjovi)

The above example should retrieve all files that don't match to "bonjovi".

Best wishes

2 Answers 2

3

You have the syntax exactly right. You just need to enable it.

shopt -s extglob 
Sign up to request clarification or add additional context in comments.

Comments

2

It's probably easiest to use grep, xargs and a regular expression. grep -v excludes lines (in this case filenames) matching a given pattern.

ls | grep -v 'bonjovi' | xargs myscripts/myprog.py 

2 Comments

Great, thanks Charles! How could I also use regular expression for the grep parameter? let's say: ls | grep -v 'bonjovi_album1' | xargs myscripts/myprog.py I made a small test, but "bonjovi_album1" is also retrieved in the output.
*bonjovi_album1* isn't a valid regular expression because there's nothing before the first *. echo bonjovi_album1 | grep -v 'bonjovi_album1*' works for me but it might not be doing what you expect. It removes anything containing bonjovi_album followed by 0 or more 1 s. In this case it's equivalent to the pattern bonjovi_album.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.