The Saigon CTT
The Linux Shell and
BASH Scripting
The Saigon CTT
Objectives
Objectives
Identify differrent Linux shell environments
Understand the redirection of input
Understand and utilize command substitution
Write and configure BASH script using
variables, flow controls interactive input,
functions, arithmetic and arrays
The Saigon CTT
Example of Script
Example of Script
$ more example_script
#!/bin/bash
/usr/bin/nmbd -D
/usr/bin/smbd -D
Shell Environment Customize
Shell Environment Customize
bash config files :
•
/etc/profile
•
~/.bash_profile, ~/.bash_login,
~/.profile, ..
Default environment variables : PS1, PS2,
HOME, LOGNAME, SHELL, PATH,
PAGER, LPDEST, PWD, DISPLAY,
MAIL, ..
set, unset, export, … commands
The Saigon CTT
Using the
Using the
bash
bashshell
shell
Alt+Fn
Pipe (|)
#ls –l *.JPG | tee file_name
#ls –al /root | grep error >error_file
Back ticks (`) or “$()”
# which passwd
/usr/bin/passwd
# ls –l `which passwd`
-r-sr-xr-x 1 root root 13476 Aug 7 /usr/bin/passwd
The Saigon CTT
Redirecting Input and Output
Redirecting Input and Output
Sometimes the output of a command is a
list (ex: ls) and we wish to execute
another command on each of the entries,
use xargs
#ls | xargs grep README
Do Not use :
#ls –al | xarg grep README
The Saigon CTT
Background jobs
Background jobs