Changes

Jump to: navigation, search

OPS235 Lab 4 - CentOS7

236 bytes added, 15:41, 10 April 2015
no edit summary
|- valign="top"
|
{{Admon/tip|Bash Shell Scripting Tips:|<br><ul><li>'''The case statement:'''<br><br>The case statement is a control-flow statement that works in a similar way as the if-elif-else statement (but is more concise). This statement presents scenerios or "cases" based on values or regular expressions (not ranges of values like if-elif-else statements). After action(s) are taken for a particular scenerio (or "case"), a break statement (''';;''') is used to "break-out" of the statement (and not perform other actions). A default case (*) is also used to catch exceptions.<br><br><u>'''Examples (try in shell script):'''</u><br><br>''read -p "pick a door (1 or 2): " pick<br>case $pick in<br>&nbsp; 1) echo "You win a car!" ;;<br>&nbsp; 2) echo "You win a bag of dirt!" ;;<br>&nbsp; *) echo "Not a valid entry"<br>&nbsp;&nbsp;&nbsp;&nbsp; exit 1 ;;<br>esac''<br><br>read -p "enter a single digit: " digit<br>case $digit in<br>&nbsp; [0-9]) echo "Your single digit is: $digit" ;;<br>&nbsp; *)&nbsp;&nbsp;&nbsp;&nbsp; echo "not a valid single digit"<br>&nbsp;&nbsp;&nbsp;&nbsp; exit 1 ;;<br>esac<br><br></li><li>'''The getopts function:'''<br><br></li></ul>x<br><br><ul><li>'''<u>Example of getopts function</u>'''<br><br></li></ul>}}
|}
13,420
edits

Navigation menu