210 likes | 320 Views
Lecture 11: Bourne Shell ( ch 8). IT244 - Introduction to Linux / Unix Instructor: Bo Sheng. Parameters and Variables. Remove a variable person= echo $person unset person. Variable Attributes. readonly variables person= zach echo $person readonly person person= helen readonly.
E N D
Lecture 11: Bourne Shell (ch 8) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng
Parameters and Variables • Remove a variable • person= • echo $person • unset person
Variable Attributes • readonly variables • person=zach • echo $person • readonly person • person=helen • readonly
Variable Attributes • declare and typeset • declare person1=max • declare –r person2=zach
Variable Attributes • declare and typeset • declare –rx person3=helen • declare –x person4
Variable Attributes • declare and typeset • declare –i COUNT
Variable Attributes • List/remove attributes • declare -r • declare -x • declare +x person4 • declare -x • declare +r person2
Keyword Variables • PATH • HOME • HOSTNAME • PS1/PS2 • PS1=* • PS1=$HOSTNAME • PS1=“\d \h \u - ” (table in Pg 310) • PS2= “---”
History • Variables • HISTSIZE • HISTFILE • HISTFILESIZE • cat ~/.bash_history • history | less • history | tail
Processes • What’s a process • Execution of a command • Shell is a process • fork() • Two identical processes, but one is the parent and the other is the child.
Processes • Execute a command sleep shell fork execute the command shell fork execute the command (background)
Processes • PID and PPID • sleep 10& • ps -f • Builtins • Variables • cat > my_script declare -r sleep 10 • ./my_script & ps -f
Expansion • History expansion • !! • Variable expansion • echo $person • echo ‘$person’ • echo “$person’
Expansion • Tilde expansion • echo ~/it244 • echo ~shengbo • echo ~xx • echo ~+ • echo ~-
Expansion • Pathname/filename expansion • echo colors* • echo zzz* • echo “colors* $person” • echo ‘colors* $person’ • var=colors* • echo ‘$var’ • echo “$var” • echo $var
Expansion • Brace expansion • echo colors.{1,2} • mkdir test{1,2,3} • ls –F • Different from file reference • ls test[1-3] • mkdir quiz[1-3] • ls hello[5-6] • ls hello{5,6}
Expansion • Command substitution • $(command) • echo $(pwd) • mypwd=$(pwd)
Expansion • Arithmetic expansion • echo 1+1 • echo $((1+1)) • echo “there are $((60*60*24)) seconds in a day” • x=10;y=20 • echo $((x*2+y/4))
Expansion • Arithmetic expansion • cat > age_check >echo "how old are you?" >read age >echo "you'll be 60 in $((60-age)) years."
Expansion • Arithmetic expansion • wc –l colors.1 • wc –l colors.1 | cut –c1-2 • echo $(( $(wc –l colors.1 | cut –c1-2) + $(wc –l colors.2 | cut –c1-2) ))
Expansion • Order of expansion • tofile=“> log” • echo hello $tofile • a=hello* • echo “$a” • echo $a