Results 1 to 3 of 3
I have been learning linux for about a year now, and I thought I knew my way around the bash shell fairly well by now, until I deleted a whole ...
- 01-22-2010 #1Just Joined!
- Join Date
- Jan 2010
- Posts
- 1
The use of parentheses in the bash shell
I have been learning linux for about a year now, and I thought I knew my way around the bash shell fairly well by now, until I deleted a whole folder worth of files on accident. Here's how it happened: I have a homework folder to which I had downloaded a good deal of files, and also had saved a bunch of my homework there. Over the course of the semester, I had inadvertently downloaded some files twice, and firefox placed a "(2)" at the end of duplicate files. I wanted to delete all of the duplicates, so I tried the following:
It did not work as expected, it deleted everything. I now know that i should have used:Code:# rm *(2)*
orCode:# rm *"(2)"*
but it's too late for that. I have since been trying to figure out exactly what the parentheses do. I am baffled because I am getting some pretty unexpected results as I play around with them. for example:Code:# rm *\(2\)*
Can someone help me understand what is happening? What do the parentheses do? Any links to sites that explain in detail would be appreciated as well.Code:# echo *(2) *() # echo *(2)* emacs-23.1.tar.bz2 final_report_merged.pdf HW%202(2).doc HW%202.doc HW%203.doc site-lisp verilog-mode.el.gz
Thanks in advance!
- 01-23-2010 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
This has to do with extended globbing, an extension of the usual meta-character set:
Please look at the section of man bash that describes shopt and extglob:Code:* ? [ ... ]
a few experiments along with that reference should explain things ... cheers, drlCode:If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized ... -- excerpt from man bash, searching for extglobWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 01-24-2010 #3
That's cool drl, I didn't know that... thanks

Parentheses are primarily used to define functions


Reply With Quote