Professional Documents
Culture Documents
COMP2101
Fall 2019
Scripting Environment
Environment variables
Shell Process
Processes have a way to store variables in their environment, which is a special part of
process memory
Environment variables are normally named using capital letters and numbers only
export VARNAME
export VARNAME=“Data”
export -n VARNAME
Lab 3 - checkMYVAR.sh
Login Shell
When you login to the system, the program that allowed you to login runs
whatever shell program is configured for your login account, typically bash for
Linux users
The first shell process started when you log onto a Linux system is called your
login shell
It is used to start other programs, manage files, and observe and control the system
If you start additional shells such as in terminal windows or by running scripts, they
are called interactive non-login shells
When your login shell process ends, you are logged out
bash Environment Files
Environment files are shell scripts that run commands to configure programs,
set variables, manipulate files, and/or send messages
Each user's environment files are kept in their home directory, and users can
create, modify, or remove them
Some are inherited from ancestor processes (e.g. login, getty, init)
$ - current process id
Testing data
Testing files
Test Command
The test command evaluates an expression and sets its exit status
based on whether the expression evaluates as true or false
The test command can also be run using the [ alias, which uses a ]
to mark the end of the expression on the command line
Putting ! in front of the test operator ( the letter with a dash in front of it ) inverts the test
Test Expressions
Test is generally used to either test data (usually in variables), or to test file attributes
Test expressions may test single things for some characteristic, or attribute - this is
known as a unary test
Test expressions may compare two things - this is known as a binary test
Unary test expressions take the form -x thing, where -x is the test operator
specifying what kind of test to perform
Binary test expressions take the form thing1 operator thing2 where operator tells
the test command what kind of comparison to perform
Scripts commonly can evaluate situations and make simple decisions about
actions to take
Complex evaluations and multi-step actions are better handled using more
sophisticated execution control commands
We may have multiple data items on which we need to perform one or more
commands, also in a loop
Conditional Script Block Execution