I have two questions about using regular expressions inside a shell.
1. Use of *
According to wikipedia page on regular expressions:
*: The asterisk indicates there is zero or more of the preceding element. For example, ab*c matches "ac", "abc", "abbc", "abbbc", and so on.
However, when I write rm test*.iso
, it will delete all files beginning by "test" and finishing by ".iso" whatever there is (or not) between "test" and ".iso". So, the file "tes.iso" will be not deleted.
If you take the abc example, according to wikipedia, "ab*c" matches "ac". Therefore rm ab*c
should delete an "ac" file. Why rm does not use regular expression as wikipedia describes them?
2. Use of - and ?
Still according to wikipedia page on regular expressions:
?: The question mark indicates there is zero or one of the preceding element. For example, colou?r matches both "color" and "colour".
+: The plus sign indicates there is one or more of the preceding element. For example, ab+c matches "abc", "abbc", "abbbc", and so on, but not "ac".
"?" seems to work like "*", that is to say "?" symbol replaces one or zero element (but not the preceding one contrary as what wikipedia says).
I don't know how to use "+" and this is my second question. I'm also interested by any tricks concerning regular expressions and rm, cp, ...
.
rm
using regular expressions (rm
doesn't know anything about regexes). It is about the shell's pathname expansion and regexes. What makes you believe that the shell treatswhatever*
as an regex? – Hauke Laging May 11 '14 at 14:29*
but that has nothing to do with regular expressions. It is called globbing. – Hauke Laging May 11 '14 at 15:16