simplifies the selection of a match when there are lists of options. A common application is Case Logic – in creating menu selections. It simplifies some scenarios. if/else/if #! /bin/bash # Program implements the structure case echo years in school” “Enter read years case $years in 1) echo “Freshman”;; 2) echo “Sophomore”;; 3) echo “Junior”;; 4) echo “Senior”;; *) echo Choice”;; “Invalid esac used to repeat commands or statements until specific condition(s) exist(s). Looping Logic – The basic elements of a looping structure are: Initialization Condition testing Iteration (increment/decrement) The basic types of looping structures are: loop a pre-condition loop that continues to loop and execute commands or while – statements as long as the given condition(s) is or are true. # Program directive to run script using the shell #! /bin/bash bash # Program implements the logic structure case count=1 while [ $count 5 ] –lt do echo = $count “Count “ let count=count+1 done loop a pre-condition loop used to loop through a range of values. E.g., for – for count in 1 2 3 4 do echo = $count “ done loop a post-condition loop that continues to loop and execute commands or until – statements as long as the given condition(s) is or are false. E.g., count=1 [ $count 5 ] –eq do echo = $count “Count “ let count=count+1 done uses positional variables through for the first through ninth command Command Line Parameters $1 $9 – line parameters. Other variables include: (name of script), (number of command line parameters), $0 $# or (all command line parameters through (exit status of last command), (process ID of $@ $* $1 $9), $? $$ the executing process).
Case Logic – simplifies the selection of a match when there are lists of options. A common application is in creating menu selections. It simplifies some if/else/if scenarios. #! /bin/bash # Program implements the case structure echo “Enter years in school” read years case $years in 1) echo “Freshman”;; 2) echo “Sophomore”;; 3) echo “Junior”;; 4) echo “Senior”;; *) echo “Invalid Choice”;; esac Looping Logic – used to repeat commands or statements until specific condition(s) exist(s). The basic elements of a looping structure are: Initialization Condition testing Iteration (increment/decrement) The basic types of looping structures are: while loop – a pre-condition loop that continues to loop and execute commands or statements as long as the given condition(s) is or are true. #! /bin/bash # Program directive to run script using the bash shell # Program implements the case logic structure count=1 while [ $count –lt 5 ] do echo “Count = “ $count let count=count+1 done for loop – a pre-condition loop used to loop through a range of values. E.g., for count in 1 2 3 4 do echo = “ $count done until loop – a post-condition loop that continues to loop and execute commands or statements as long as the given condition(s) is or are false. E.g., count=1 [ $count –eq 5 ] do echo “Count = “ $count let count=count+1 done Command Line Parameters – uses positional variables $1 through $9 for the first through ninth command line parameters. Other variables include: $0 (name of script), $# (number of command line parameters), $@ or $* (all command line parameters $1 through $9), $? (exit status of last command), $$ (process ID of the executing process).
os_studyguide3.docx