Changes

Jump to: navigation, search

OPS235 Lab 1 - CentOS7 - VMware

22 bytes removed, 08:18, 22 May 2016
no edit summary
|- valign="top"
|
{{Admon/note|Bash Shell Reference Guide:|<br>'''<u>She-bang Line</u>'''<ul><li>Forces shell script to run in a specific Shell</li><li>Some shell syntax not backward compatible</li><li>'''#!''' must be at beginning of first line of shell script</li><li>Example: '''#!/bin/bash'''<br><br></li></ul>'''<u>Variables</u>'''<br><blockquote>'''Environment'''<ul><li>System-wide or "global" variable</li><li>Usually appear in UPPERCASE letters</li><li>Can view with command: '''set &#124; more'''</li><li>'''$''' in front to expand variable to value<li>Examples: '''USER''', '''PATH''', '''HOME''', '''SHELL'''<br></li></ul></blockquote><blockquote>'''User-defined''' <ul><li>Variable created by user (command line, scripting)</li><li>Examples:<br>''myVar&#61;"my value"; readonly myVar; export myVar''<br>''read -p "enter value: " myVar''<br></li></ul></blockquote><blockquote>'''Positional parameters'''<ul><li>Assign values with set command or shell script arguments</li><li>These variables are numbered (eg. $1, $2 ... $10}</li><li>Special parameters: $*, $@, $#, $$, $?<br></li></ul></blockquote>'''<u>Command Substitution</u>'''<ul><li>Useful method to expand output from a command to be used as an argument for another command.</li><li>Examples:<br>''file $(ls)''<br>''set $(ls);echo $#;echo $*''<br>''echo "hostname: $(hostname)"''<br><br></li></ul>'''<u>Logic Control Flow Statements</u>'''<ul><li>'''$?''' variable true (0) if command runs; otherwise is false (non-zero)</li>Example:<br>''if echo $myVar &#124; grep "match"''<br>''then''<br>''echo "Match"''<br>''fi''<br></li><li>Can use if stmt with test commandto test conditions. Square brackets '''[ ]''' is short-cut for test command (args contained inside with spaces). The '''exit''' command can be used to terminate the shell script with a false value.<br><br>'''<u>Examples</u>'''<br>Example:<br>''if [ $USER &#61; "root" ]''<br>''then''<br>&nbsp;''echo "You must be root" >&amp;2''<br>&nbsp;''exit1''<br>''fi''<br>Can use '''if''' / '''if-else''' / '''if-elif-else''' statements with brackets. <br># For number comparison: use:<br># -gt,-ge, -lt, -le, -eq, -ne<br><br>''if [ $age -gt 65 ]''<br>''then''<br>&nbsp;''echo "retire"''<br>''else''<br>&nbsp;''echo "don't retire"''<br>''fi''<br><br>''if [ $grade -gt 79 ]''<br>''then''<br>&nbsp;''echo "You get Good Mark"''<br>''elif [ $grade -gt 49 ]''<br>''then''<br>&nbsp;''echo "You pass"''<br>''else''<br>&nbsp;''echo "You fail"''<br>''fi''<br></li></ul>}}
|}
13,420
edits

Navigation menu