Introduction to shells
Overview
Why do we need a shell?
Shell
syntax
Types of shell
command
Simple
commands
Pipelines
Grouping
commands
Exit status
List commands
Arithmetic
Operators and
functions
Making
decisions
The 'test'
statement
Operators used by 'test'
The 'if'
statement
Loops
'For' loops
'While' and
'until' loops
Searching for files
Arguments to
'find'
Formatted output
Arguments to
'printf'
Passing information to
scripts
Scripts with
arguments
Parameter
expansion
Summary
Exercises
|
Operators used by 'test'
File operators
-d filename |
True if filename exists and is a directory |
-e filename |
True if filename exists |
-f filename |
True if filename exists and is
regular |
-r filename |
True if filename exists and is readable |
-s filename |
True if filename exists and has size non-zero |
-w filename |
True if filename exists and is writable |
-x filename |
True if filename exists and is executable |
Note that a regular file is essentially one that is not a
directory; there are other sorts of non-regular files, such as
FIFO files, but they do not concern us here.
String operators
-n string |
True if string has length non-zero |
-z string |
True if string has length zero |
string |
True if string is not null |
s1 = s2 |
True if strings s1 and s2 are equal |
s1 != s2 |
True if strings s1 and s2 are not equal |
Arithmetic operators
n1 -eq n2 |
True if numbers n1 and n2 are equal |
n1 -ne n2 |
True if numbers n1 and n2 are not equal |
n1 -gt n2 |
True if n1 is greater than n2 |
n1 -ge n2 |
True if n1 is greater than or equal to
n2 |
n1 -lt n2 |
True if n1 is less than n2 |
n1 -le n2 |
True if n1 is less than or equal to n2 |
|