UNIX / Linux Shell Scripting Tutorial

Unix / Linux Bourne / Bash shell scripting book Buy this book as a 75-page PDF document.
Read the sample. All the content, available offline, with examples, no adverts, and convenient to print.

UNIX/Linux Shell CheatSheet : free A4 PDF (52Kb) | PNG (90Kb)

Unix / Linux Shell Scripting Tutorial

4. Variables - Part I 1. Intro 2. Philosophy 3. A First Script 4. Variables - Part I 5. Wildcards 6. Escape Characters 7. Loops 8. Test 9. Case 10. Variables - Part II 11. Variables - Part III 12. External Programs 13. Functions 14. Hints and Tips 15. Quick Reference 16. Interactive 17. Exercises 6. Escape Characters

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.


4. Variables - Part I 1. Intro 2. Philosophy 3. A First Script 4. Variables - Part I 5. Wildcards 6. Escape Characters 7. Loops 8. Test 9. Case 10. Variables - Part II 11. Variables - Part III 12. External Programs 13. Functions 14. Hints and Tips 15. Quick Reference 16. Interactive 17. Exercises 6. Escape Characters
Suggested books: Recommended Reading
StumbleUponStumbleUpon | del.icio.usdel.icio.us

Site Links



1. Intro
2. Philosophy
3. A First Script
4. Variables - Part I
5. Wildcards
6. Escape Characters
7. Loops
8. Test
9. Case
10. Variables - Part II
11. Variables - Part III
12. External Programs
13. Functions
14. Hints and Tips
15. Quick Reference
16. Interactive
17. Exercises
18. Forum
19. Recommended Books




My blog has tips about how to use Unix and Linux commands XML



contact