Introducion to Shell Scripting
By AECC-UPRRP
Get down & dirty with the Terminal
That’s All!
Thanks for Coming
Now you can be this guy too!
THE SHELL
Usual file system structure and usage:
Table of Contents
Permissions:
Shebang ( #! ) :
Standard streams
stdin
stdout
stderr
stdin ( ) :
stdout ( ) :
stderr ( ) :
These can all be redirected!
< > << >> |
Piping and Redirecting
Piping:
Redirecting:
* we are defining these concepts in the context of bash
$PATH
$PATH: an enviromental variable. Contains the directories where executables are stored
Check Enviromental Vars: `env`
Check $PATH: `echo $PATH`
$PATH cont.
`export PATH=$PATH:<directory>`
`PATH=$PATH:<directory>`
Parsing
Side note:�Extremely important for compilers
Regular expressions (regex)
Regular expressions (regex) cont.
Variety of Shells
Shells :
*: Not *nix. Similar-ish, but EVERYTHING is an Object (I/O).
Scripting:
What’s the point?
Scripting cont. :
Choose your favorite text editor. It’s probably better if you’re comfortable with a shell text editor such as vi/vim, nano, emacs (we’ll cover this more in depth in another workshop :) )
Bash...tricky sintax:
B
Bash...tricky sintax pt 2:
Conditionals:
if [ <condition> ]; then
<stuff>
elif (( <arithmetic condition> )); then
<stuff>
else
<stuff>
fi
** use [ ] or test
A
Bash...tricky sintax pt 3:
- Arithmetic operators:
- Logical operators:
S
Bash...tricky sintax pt 4:
for <iterations>
do
<stuff>
done
** can be:
in {i..n}
in <dir> or in <command_out>
C style
while <condition>
do
<stuff>
done
H
Workshop :
Go to: http://bit.ly/aecc-shell
Helpful list of more advanced shell commands:
AECC’s Favorite/Most used Commands or packages and favorite shell:
Some more resources: