1 / 19

Lecture 12: Bourne Shell ( ch 8)

Lecture 12: Bourne Shell ( ch 8). IT244 - Introduction to Linux / Unix Instructor: Bo Sheng. Expansion. History expansion !! Variable expansion echo $person echo ‘$person’ echo “$person’. Expansion. Tilde expansion echo ~/it244 echo ~ shengbo echo ~xx echo ~+ echo ~-. Expansion.

clyde
Télécharger la présentation

Lecture 12: 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 12: Bourne Shell (ch 8) IT244 - Introduction to Linux / Unix Instructor: Bo Sheng

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

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

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

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

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

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

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

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

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

  11. Readline Completion • Command completion • ec[TAB] • bz[TAB] • bc[TAB] • Pathname completion • ls ~/it2[TAB]/hel[TAB] • Variable completion • echo $HO[TAB]

  12. Aliases • Short names • alias myls=‘ls -a’ • No recursion • alias rm=‘rm –i’ • alias ls=‘ls -F’ • alias ll=‘ls –l’ • alias ls=‘ls -l’ • unaliasrm • alias ls=ls

  13. Aliases • Inside quotes • echo $PWD • alias mypwd1=“pwd is $PWD” • alias mypwd2=‘pwd is $PWD’ • cd /home • mypwd1 • mypwd2

  14. Re-execute and Edit Commands • Fix commands (fc) • fc -l • fc -l [first [last]] • fc –l 100 105 • fc –l 500 • fc –l echo ls • fc –l cat

  15. Re-execute and Edit Commands • Fix commands (fc) • fc -s # • echo hello* • fc –l • fc -s # • fc -s hello=color #

  16. Re-execute and Edit Commands • Exclamation point (!) • Table in Pg331 • !! • !498 • !-3 • !e • !?ch

  17. Functions • What is a function? • function whoson() >{ >date >echo “Current Users:” >who >}

  18. Functions • Compare a function to a script • Functions are stored in memory • Faster • No permissions • Functions are executed in the same shell • Remove a function • unset

  19. Functions • A function and script with the same name • Shell executes the function first • Example echo “echo script”>my_script function my_script() { echo function } • A function and variable with the same name • unset removes the variable first

More Related