Open main menu

CDOT Wiki β

Changes

OPS235 Lab 2 - CentOS7

2 bytes removed, 08:06, 2 April 2015
no edit summary
|- valign="top"
|
{{Admon/tip|Bash Shell Scripting Tips:|<br><ul><li>'''Iteration Inputting Text:'''<br><br> There are 3 types of variables that can be used in shell scripting: '''ENVIRONMENT''' (eg. $USER), '''user-defined''' ($varName), and '''positional parameters''' (eg. $1, $2... containing arguments after shell script or by using set command (loopseg. '''set $(ls)''' ). Using dollar sign ('''$''') in front of variable expands the value assigned.<br><br></li><li>'''Loops (iteration):'''<br><br>x<br><br>'''<u>Examples</u>'''<br><br>'''if [ $USER &#61; "root" ]'''<br>'''then'''<br>&nbsp;'''echo "You must be root" >&amp;2'''<br>&nbsp;'''exit1'''<br>'''fi'''<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><li>'''Regular ExpressionsLoops and Testing'''<br><br>Shell scripts have evolved of the past 40 years. To avoid running a newer shell script on an older shell, it is recommended to force running the shell script in the correct shell. In order to do this, on the first line at the very beginning of the shell script, you add the '''#!''' ('''# as in "shhhh" - a comment''', and''' ! is referred to as "bang" run a commmand''': in this case, '''run the command: /bin/bash'''). You can issue the Linux command '''which bash''' to get the correct location. If there is no bash shell on that machine, the shell script will not run (as a precaution - the Linux admin will know how to make a fix to the shell script if required)<br>. </li><li>'''Inputting Text:'''<br><br> There are 3 types of variables that can be used in shell scripting: '''ENVIRONMENT''' (eg. $USER), '''user-defined''' ($varName), and '''positional parameters''' (eg. $1, $2... containing arguments after shell script or by using set command (eg. '''set $(ls)''' ). Using dollar sign ('''$''') in front of variable expands the value assigned.<br><br></li></ul>}}
|}
13,420
edits