07 Laboratory Exercise 1
07 Laboratory Exercise 1
Laboratory Exercise
Shell Scripting 1
Objectives:
Materials:
Procedures:
1. Open the “Terminal” program, and create a file named” Hello” using the vi editor by executing:
$vi Hello
2. Once the file is opened, proceed edit mode by pressing the “i” key and then add the following
information listed below. If you want to move into another line, you need to go out from edit mode
by pressing Escape key and then you can use the following keys to move inside a file.
3. Once the file is saved, modify the file access permission such that it can be executed.
$ ls -l.
This command will give a long list of files in your current directory. The output should look like this:
Here is the information about all the listed columns in the “ls –l” commands:
First Column - represents file type and permission given on the file.
Second Column - represents the number of memory blocks taken by the file or directory.
Third Column - represents the owner of the file.
Fourth Column - represents the group of the owner.
Fifth Column - represents file size in bytes.
Sixth Column - represents date and time when this file was created or modified last time.
Seventh Column - represents file or directory name.
4. All that is left to do is to execute the script file. These are the following ways that scripts can be
executed:
• $ bash Hello
• $ sh Hello
• $ ./Hello (note: This mode of execution needs elevation, try doing chmod command first)
Under shell scripting, it is possible that the user may use ordinary commands such as ls, cd, cal,
who, whoami, etc. that may be necessary for a certain script. Note: Use the ` (backquote) sign,
not the ‘ (single quote) sign. A backquote is generally found with the tilde (~) key or above the
TAB key.
$ vi inform
# Script to print user info, current date & time
clear
echo "Hello "
whoami
echo "Today is `date`”
echo "Number of user login : `who | wc -l`”
echo " Calendar"
cal
5. Execute the script file: $ bash inform
GRADING RUBRIC
Criteria/Scoring 02-25 26 - 50 51 - 75 76 – 100 Score
Procedure No output Incorrect Correct execution Correct scripting /100
Execution scripting of bash scripts but with the correct
syntaxes. Error with incorrect execution of
in executing scripting syntaxes. bash scripts.
both scripts.
Total /100