1 / 21

Lecture 11: Bourne Shell ( ch 8)

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.

lei
Download Presentation

Lecture 11: Bourne Shell ( ch 8)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 11: Bourne Shell (ch 8) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng

  2. Parameters and Variables • Remove a variable • person= • echo $person • unset person

  3. Variable Attributes • readonly variables • person=zach • echo $person • readonly person • person=helen • readonly

  4. Variable Attributes • declare and typeset • declare person1=max • declare –r person2=zach

  5. Variable Attributes • declare and typeset • declare –rx person3=helen • declare –x person4

  6. Variable Attributes • declare and typeset • declare –i COUNT

  7. Variable Attributes • List/remove attributes • declare -r • declare -x • declare +x person4 • declare -x • declare +r person2

  8. Keyword Variables • PATH • HOME • HOSTNAME • PS1/PS2 • PS1=* • PS1=$HOSTNAME • PS1=“\d \h \u - ” (table in Pg 310) • PS2= “---”

  9. History • Variables • HISTSIZE • HISTFILE • HISTFILESIZE • cat ~/.bash_history • history | less • history | tail

  10. 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.

  11. Processes • Execute a command sleep shell fork execute the command shell fork execute the command (background)

  12. Processes • PID and PPID • sleep 10& • ps -f • Builtins • Variables • cat > my_script declare -r sleep 10 • ./my_script & ps -f

  13. Expansion • History expansion • !! • Variable expansion • echo $person • echo ‘$person’ • echo “$person’

  14. Expansion • Tilde expansion • echo ~/it244 • echo ~shengbo • echo ~xx • echo ~+ • echo ~-

  15. Expansion • Pathname/filename expansion • echo colors* • echo zzz* • echo “colors* $person” • echo ‘colors* $person’ • var=colors* • echo ‘$var’ • echo “$var” • echo $var

  16. 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}

  17. Expansion • Command substitution • $(command) • echo $(pwd) • mypwd=$(pwd)

  18. 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))

  19. Expansion • Arithmetic expansion • cat > age_check >echo "how old are you?" >read age >echo "you'll be 60 in $((60-age)) years."

  20. 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) ))

  21. Expansion • Order of expansion • tofile=“> log” • echo hello $tofile • a=hello* • echo “$a” • echo $a

More Related