Assignment - Shell Programming
A. Learning Outcome
Upon successful completion of this assignment, you will be familiar with:
Bash Shell Programming
How shell programs are executed
The use of shell variables
Some basic coding principles
B. Assignment Description
Write a Bash shell script that displays the following menu and prompts for one-character input to
invoke a menu option, as shown.
a. Display the present working directory
b. List names of the files in a given directory
c. Display today's date and time
d. Display whether a file is a ordinary file or a directory
e. Execute a command line
f. Exit the program
Your program should look as follows:
*********************************************************************
Please choose from the following options; type the option
number and hit the <Enter> key.
a or A To display the current directory
b or B To list names of the files in a given directory
c or C To display today's date and time
d or D To display whether a file is a simple file or directory
e or E To execute a command line.
q or Q To exit the program.
*********************************************************************
Enter your choice and hit <Enter>: a
/home/nghia/Test/Shell
Hit <Enter> to continue.
Enter your choice and hit <Enter>: b
Please enter the directory path: /sys
total 4
drwxr-xr-x 12 root root 0 2009-07-18 13:18 .
drwxr-xr-x 21 root root 4096 2009-06-26 16:07 ..
drwxr-xr-x 2 root root 0 2009-07-18 13:18 block
drwxr-xr-x 21 root root 0 2009-07-18 13:18 bus
drwxr-xr-x 46 root root 0 2009-07-18 13:18 class
drwxr-xr-x 4 root root 0 2009-07-18 21:13 dev
drwxr-xr-x 10 root root 0 2009-07-18 13:18 devices
drwxr-xr-x 4 root root 0 2009-07-18 13:18 firmware
drwxr-xr-x 4 root root 0 2009-07-18 13:18 fs
drwxr-xr-x 6 root root 0 2009-07-18 13:18 kernel
drwxr-xr-x 97 root root 0 2009-07-18 13:18 module
drwxr-xr-x 2 root root 0 2009-07-18 13:18 power
Hit <Enter> to continue.
Enter your choice and hit <Enter>: b
Please enter the directory path: adirectory
adirectory is not a directory.
Hit <Enter> to continue.
Assigment1 Page 1
Enter your choice and hit <Enter>: c
Sat Jul 18 21:15:17 ICT 2009
Hit <Enter> to continue.
Enter your choice and hit <Enter>: d
Please enter file name: afile
afile does not exist, or it is neither an ordinary file not a
directory.
Hit <Enter> to continue.
Enter your choice and hit <Enter>: d
Please enter file name: case_demo
case_demo is an ordinary file.
Hit <Enter> to continue.
Enter your choice and hit <Enter>: d
Please enter file name: dir1
dir1 is a directory.
Hit <Enter> to continue.
Enter your choice and hit <Enter>: e
Please enter a command to be executed: df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 7.5G 2.8G 4.4G 39% /
tmpfs 249M 0 249M 0% /lib/init/rw
varrun 249M 112K 249M 1% /var/run
varlock 249M 0 249M 0% /var/lock
udev 249M 140K 249M 1% /dev
tmpfs 249M 76K 249M 1% /dev/shm
lrm 249M 2.2M 247M 1% /lib/modules/2.6.28-13-
generic/volatile
Hit <Enter> to continue.
Enter your choice and hit <Enter>: q
Bye now!
C. Submission Requirements
At the beginning of your program, include comments with the following information formatted
neatly, and reflecting accurate information about you.
#Assignment: Shell Programming
#Class ID: YourClassID
#Student ID: YourStudentID
#Student Name:YourName
#Source File: YourName_YourStudentID_ShellProgramming.sh
Assigment1 Page 2