You are on page 1of 3

Jaypee Institute of Information Technology University, Noida.

Document Title: Laboratory Sheet 6&7 (Jan 2011)


Subject: Unix Programming Lab (B.Tech C.S/IT II SEM)
Course Code: 10B17CI307
______________________________________________________________________
Instructions: (1) Work performance of every student at the end of each Laboratory session would be
graded and recorded.
(2) All lab assignments carry marks.
(3) All questions will be evaluated
(4) Notes provided are meant only for guidelines. Notes solely will not cover the entire
syllabus. Read prescribed books also.
(5) Reference books include: UNIX : The Textbook by Sarwar, Koretsky, Sawar.
and Unix Concepts and Applications by Sumtiabh Das, Tata McGraw Hill
___________________________________________________________________
Ques:1 Execute the following shell script and interpret its output.
#!/bin/bash
##### Constants
TITLE="System Information for $HOSTNAME"
RIGHT_NOW=$(date +"%x %r %Z")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"
##### Functions
function system_info
{
# Temporary function stub
echo "function system_info"
}
function show_uptime
{
# Temporary function stub
echo "function show_uptime"
}
function drive_space
{
# Temporary function stub
echo "function drive_space"
}
function home_space
{
# Temporary function stub
echo "function home_space"
}
##### Main
cat <<- _EOF_
<html>
<head>
<title>$TITLE</title>
</head>
<body>
<h1>$TITLE</h1>
<p>$TIME_STAMP</p>
$(system_info)
$(show_uptime)
$(drive_space)
$(home_space)
</body>
</html>
_EOF_

Ques 2: Design a shell script to print the comment “number is negative” if a number
entered by a user is less than 0, to print “number is positive”if number is greater
than 0 otherwise “number entered is 0”.
Try above script as follows:
$ chmod 755 elf
$ ./elf 1
$ ./elf -2
$ ./elf 0
$ ./elf a
and then explain its output.

Ques 3: Execute the following script and note down its drawbacks:
echo -n "Enter a number between 1 and 3 inclusive > "
read character
if [ "$character" = "1" ]; then
echo "You entered one."
else
if [ "$character" = "2" ]; then
echo "You entered two."
else
if [ "$character" = "3" ]; then
echo "You entered three."
else
echo "You did not enter a number"
echo "between 1 and 3."
fi
fi
fi

Ques 4: Design a shell script that identifies whether a user has entered a digit or a
letter and reflects back the same to the standard output.

Ques 5: Device a menu driven program to convert one number system to


another( for example from octal to hexadecimal).

Ques 6: Design a shell script to print chess board on screen.

Ques 7: Construct a shell script to obtain the following pattern on the screen:
Ques 8: Parse the output of the following code in a shell script
while [ $# -ge 1 ]; do
case $1 in
-c*) rate=`echo $1 | cut -c3-`;;
-c) shift; rate=$1 ;;
-p*) prefix=`echo $1 | cut -c3-`;;
-p) shift; prefix=$1 ;;
-*) echo $Usage; exit 1 ;;
*) disks=$*; break ;;
esac

shift

done

You might also like