Download presentation
Presentation is loading. Please wait.
1
CHAPTER 8 (skip 299-310, 333-354) CHAPTER 10
John Carelli, Instructor Kutztown University
2
Interactive login shell
First shell to provide a prompt upon login Executes the following in order /etc/profile .bash_profile .bash_login .profile Interactive nonlogin shell When a new terminal is opened only executes .bashrc source filename execute commands in named file OR execute it as a shell script (next)
3
Shell Scripts (again) Shell Script: an executable (text) file that contains shell commands. When the shell script is run, the commands in it get executed bash script #!/bin/bash Must be executable # comments execution in current shell with . (dot) changes to variables persist in current shell ex: testvar
4
Variable name Assignment Display Array variables Declare statement
$ Array variables ${name[*]} … or ${#name[*]} … or ex: arrayvars Declare statement declare varname declare –r varname # readonly – like const unset
5
Single quote ' Double quote “ Backslash \ metacharacter “escape” Back quote ` command substitution ex: quotescript
6
alias unalias Quotes in aliases only matters if alias contains a command substitution single: substitution occurs when executed double: substitution occurs when created ex: aliases
7
Arithmetic Expressions
Double parenthesis evaluate an arithmetic expression syntax: (( arithmetic expression )) (( z = x + y )) Can drop $ in variable names ex: arith
8
Operators if – then - fi if-else elif ex: operators Test and []
Arithmetic Relational String comparison -n -z File testing if – then - fi if-else elif ex: operators
9
Control Statements while for until break continue ex: looping case
select ex: menu (see also: getopt) 8
10
Command-line arguments shift ex: shifting
$# Number of positional parameters $$ PID $? Exit status of most recently executed command $0 Program name $1 - $n Positional parameters $* All positional parameters
11
Definition Arguments return export there is no scoping – variables are global except for cmd line args (can’t change those) ex: functest
12
type read exec trap
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.