Unix Shell Available
Determining Unix Shell
Shell Scripts Unix
Interpreted Compiled Programs
Understanding Scripting Options
Shell Script Macro
Built in Components
Input Output Tools
Shell Script Tests
Regex Define Patterns
Shell Program Components
Writing First Script
Interactive Shell Script
Defining Script File
Using Text Editor
Read Input Command
Including Comments Scripts
Setting File Permissions
Running Command Line
Working With Variables
Command Line Arguments
Predefined System Variables
Syntax Affects Interpretation
Using Strings Variables
Performing Math Variables
Using Array Variables
Regular Expression - Exercise
Practice using Regular Expressions
Use regular expressions with common UNIX commands.
This exercise is worth 2 points.
You need access to a UNIX command line for this exercise, either through the DispersedNet account that you establishedcin Module 1, or though another UNIX system. The -d option is used with the
command in this exercise to list the names of directories without listing their contents.
cLog in to your UNIX Lab account (or other UNIX account that you have access to).
Change to the /etc directory (or another directory containing many files on your system).
command to list all files in the directory that begin with the letter “s”.
ls -d s*
command to list all files in the directory that have “e” as the second letter.
ls -d .e*
command to list all files that begin with any one of the letters “h” “i” or “l”.
ls -d [hil]*
command with the -c option to count the number of lines in the /etc/termcap file that begin with an “N” (you can leave out the -c option if you want to view the actual lines from the file).
grep -c “^N” termcap
Using quotation marks around a regular expression prevents the shell from interpreting any special characters (like ^) before passing the expression to the
command. Quotation marks are a good idea if a regular expression is complex or does not appear to be working properly.
Experiment with other regular expressions using the
commands if you wish. Log out of your UNIX Lab account when you have finished.