.:
man cat less grep sed find xargs echo
sort uniq wc
./sh:
cd io redirect pipes variables exit codes
cmd substitution if for while wildcards
man workshop
workshop(1) fhLUG
NAMEworkshop – a little bit of shell scripting
SYNOPSISworkshop [questions ...]
DESCRIPTION
This workshop should give a rough overview about the
possibilities one has with shell scripting to automate tasks and make
life generally easier.
If executed without questions it will just output a bunch of facts
which will become boring rather quickly. If passed one or more
questions it tries to answer them in a funny but interesting way on stdout.
EXIT STATUS0 This command returns successfully most of the time.
1 This command should not fail.
2 This is an indication that something is seriously wrong.
SEE ALSO
More information can be found at http://fhLUG.at.
HISTORY
This is the first time this workshop was held.
BUGS
Exit status might not be correct.
fhLUG June, 2012
Command basics
Commands are searched from special directories ($PATH)
To execute command from current directory, use the relative path (./cmd)
Most commands can take parameters
Parameters usually start with a hyphen -
Last parameter is often a file name
If omitted, most commands read from stdin
$ ls # list directory contents
$ ls -l # long information
$ grep pattern file # grep in file
$ grep pattern # grep in stdin
cat file
This is the content of the file. It is simply printed to stdout (the terminal).
`tac' prints a file's lines in reverse order
Other ways to display a file's contents is `more' and
`less'. They even allow you to scroll through a file.
grep 'scroll' file
They even allow you to scroll through a file.
ls | grep '^.a'
man
cat
xargs
Regular expressions (man grep)
Basic (grep -G):
. Any single character
\. A single period character
[ab1-5] Any character inside the brackets
^ $ Match beginning and end of line, respectively
Extended (grep -E):
? * + Optional, zero or more, one or more
{n,m} Match at least n, no more than m times
(...) Group patterns
sed 's/[tT]erminal/console/' file
This is the content of the file. It is simply printed to stdout (the console).
...