[go: up one dir, main page]

0% found this document useful (0 votes)
377 views2 pages

07 Laboratory Exercise 1

This document provides the objectives, materials, and procedures for a shell scripting laboratory exercise. The exercise aims to teach students how to create and execute shell scripts using bash commands. Students will create two scripts - one called "Hello" that prints personal information, and another called "inform" that prints user information, date, number of logins, and a calendar. The scripts are created using vi editor and executed using bash commands.

Uploaded by

esperanza123231
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
377 views2 pages

07 Laboratory Exercise 1

This document provides the objectives, materials, and procedures for a shell scripting laboratory exercise. The exercise aims to teach students how to create and execute shell scripts using bash commands. Students will create two scripts - one called "Hello" that prints personal information, and another called "inform" that prints user information, date, number of logins, and a calendar. The scripts are created using vi editor and executed using bash commands.

Uploaded by

esperanza123231
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

IT1917

Laboratory Exercise
Shell Scripting 1
Objectives:

At the end of the exercise, the students should be able to:

 Use proper commands for shell scripts construction; and


 Execute scripts using bash commands.

Materials:

 Latest version of VirtualBox


 Ubuntu 16.04 ISO – Linux (Installed as Virtual Image)

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.

#This is my first script


clear
echo “I am <Student’s Nickname>.”
echo “I am <Real Age> years old.”
echo “My full name is <…>.”
echo “From <Course> - <Section>.”
echo “My motto in life is: <…>.”
echo “_“
echo “My goal is to graduate from this school.”
#echo “Hidden from timeline!”
Note: The # symbol in shell scripting is used as a REMARK. This simply means that any command
or statement placed after the # symbol will be disregarded. The # symbol is useful for
inserting comments on the program.

3. Once the file is saved, modify the file access permission such that it can be executed.

$ chmod 755 Hello


This simply means that the owner of the file will have full access (Read, Write, and Execute).
Confirm that the permission has been changed by simply typing the command:

$ ls -l.

This command will give a long list of files in your current directory. The output should look like this:

07 Laboratory Exercise 1 *Property of STI


Page 1 of 2
IT1917

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

07 Laboratory Exercise 1 *Property of STI


Page 2 of 2

You might also like