PDA

View Full Version : [SOLVED] bash bug?



Westerberg
October 22nd, 2007, 07:50 PM
From the bash man pages:


Composite patterns may be formed using one or more of the following sub-patterns:
. . .
!(pattern-list)
Matches anything except one of the given patterns
In other words, you can include all patterns except the few you want to exclude.
E.g., in a directory containing a mix of .html, .pdf, .avi, and .txt files, you should be able to delete all files except *html by entering:



james@james-desktop:~/Documents$ rm !(*html)
bash: !: event not found

Anyone know what's going on?

digitalbenji
October 22nd, 2007, 07:58 PM
I just tested this by creating a folder and touching several randomly ending files in it, and only one with a .html extension. It worked perfectly for me.

bash --version
GNU bash, version 3.2.13(1)-release (i486-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.


Maybe you have an older version or something? I did this on a 7.04 box as well. I would be careful about using rm with pattern matching, but thats just me, and I don't like deleting things accidentally (not saying you do).

duff
October 22nd, 2007, 07:59 PM
# shopt -s extglob

Westerberg
October 22nd, 2007, 09:29 PM
That worked. Thanks.

digitalbenji
October 23rd, 2007, 02:51 PM
could you give an explanation of that code please?

duff
October 23rd, 2007, 08:42 PM
shopt -- shell options
-s -- set variable
extglob -- extended glob rules

run "shopt" to see all variables. Use -s to set a variable, -u to unset, and the bash man page to an explianation.

digitalbenji
October 24th, 2007, 05:27 PM
Neat, thanks.