Click Here to buy the full 72-page PDF for only £4.99, $9.99 or €6.99,
or the Kindle eBook (UK here - more countries and details here)

5. Wildcards

Wildcards are really nothing new if you have used Unix at all before.
It is not necessarily obvious how they are useful in shell scripts though. This section is really just to get the old grey cells thinking how things look when you're in a shell script - predicting what the effect of using different syntaxes are. This will be used later on, particularly in the Loops section.
Think first how you would copy all the files from /tmp/a into /tmp/b. All the .txt files? All the .html files?
Hopefully you will have come up with:
$ cp /tmp/a/* /tmp/b/
$
cp /tmp/a/*.txt /tmp/b/
$
cp /tmp/a/*.html /tmp/b/
Now how would you list the files in /tmp/a/ without using ls /tmp/a/?
How about echo /tmp/a/*? What are the two key differences between this and the ls output? How can this be useful? Or a hinderance?
How could you rename all .txt files to .bak? Note that
$ mv *.txt *.bak

will not have the desired effect; think about how this gets expanded by the shell before it is passed to mv. Try this using echo instead of mv if this helps.
We will look into this further later on, as it uses a few concepts not yet covered.

Click Here to buy the full 72-page PDF for only £4.99, $9.99 or €6.99,
or the Kindle eBook (UK here - more countries and details here)

Steve's Bourne / Bash shell scripting tutorial
Share on Twitter Share on Facebook Share on LinkedIn Share on Identi.ca Share on StumbleUpon

Get the Book:

My Shell Scripting Book:
    Shell Scripting, Expert Recipes for Linux, Bash and more
is available online and from all good booksellers.

Buy my 600-page Shell Scripting Book...
DefectiveByDesign.org
From Amazon USA:

From Amazon UK:

For Kindle:

DefectiveByDesign.org
Or from other retailers

Facebook:

You can also join a Shell Scripting community on Facebook:



Get the Tutorial as a PDF:

Shell Scripting Tutorial
Buy the 72-page PDF (£4.99 / $9.99 / €6.99) of this tutorial
(Free Sample)

Get the Tutorial on Kindle:

For Kindle from Amazon USA:
For Kindle from Amazon UK:

And you can always Download my Free Shell Scripting Cheatsheet PDF

DefectiveByDesign.org