Changes

Jump to: navigation, search

OPS235 Lab 1 - CentOS7

144 bytes added, 10:23, 1 April 2015
no edit summary
<ol><li value="14">Here are some more "complex" Bash Shell scripts, that perform the same task. Although you are not require to understand some of these other tricks, it is recommended that you view the contents of the scripts and save them for future consideration or exmaples.</li><li>The <b><code>wget</code></b> command can be used to quickly download files from the Internet. Issue the following command:<blockquote><b><code><span style="pointer-events: none;cursor: default;color:#3366CC;font-size:1.2em;">wget https://scs.senecac.on.ca/~murray.saul/text-report.bash</span></code></b></blockquote></li><li>Verify that the file '''text-report.bash''' was downloaded to your current directory.</li><li>Assign read and execute permissions for this file by issuing the command: <b><code>chmod u+rx text-report.bash</code></b></li><li>Run this Bash Shell script by issuing the command: <b><code>./text-report.bash</code></b></li><li>Check to see if it created a report in your current directory. What is the purpose of the report?</li><li>Use the <b>vi</b> text editor to view the contents of the file <b>text-report.bash</b>. Can you understand how this script works?<br><br></li><li>Use the <b><code>wget</code></b> command to download, study, and run the following shell scripts on-line:<blockquote><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">https://scs.senecac.on.ca/~murray.saul/report.bash<br>https://scs.senecac.on.ca/~murray.saul/report3.bash</span></code></b></blockquote></li><li>Try to understand what these Bash Shell scripts do.</li><li>You have completed lab1. Proceed to Completing The Lab, and follow the instructions for "lab sign-off".</li></ol>
|width="40%"|{{Admon/tip|Bash Shell Scripting Tips:|<br><ul><li>'''Variables:'''<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><li>'''Logic Control Flow Statements:'''<br><br>The '''test''' command can be used to see if a condition is true or false<br>(i.e. test $USER &#61; "root") . The '''$? ''' special shell variable stores the result (zero if true, non-zero if false). Square brackets '''[ ] ''' can be used to represent the test command with the condition <u>inside</u> the brackets (spaces separating brackets).Can use '''if''' / '''if-else''' / '''if-elif-else''' statements with brackets. The '''exit''' command can be used to terminate the shell script with a false value.<br><br>Examples:<pre>if [ $USER != "root" ]
then
command(s) (if true)echo "You must be root" >&2 exit1
fi
if [ $age - gt 65 ]
then
echo "retire"
13,420
edits

Navigation menu