0% found this document useful (0 votes)
127 views

Lab 6&7

This document contains instructions for a Unix programming lab assignment. It includes 8 questions asking students to write and execute shell scripts to perform tasks like: 1) Interpreting the output of a shell script that prints system information, 2) Checking if a user-entered number is positive, negative, or zero, 3) Noting the drawbacks of a script using nested if/else statements, 4) Identifying if a user entered a digit or letter, 5) Converting between number systems like octal and hexadecimal, 6) Printing a chess board pattern, and 7) Parsing the output of a code sample using a while loop. Students are advised to complete the tasks and assignments in order to be graded on their lab work.

Uploaded by

Aditya Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views

Lab 6&7

This document contains instructions for a Unix programming lab assignment. It includes 8 questions asking students to write and execute shell scripts to perform tasks like: 1) Interpreting the output of a shell script that prints system information, 2) Checking if a user-entered number is positive, negative, or zero, 3) Noting the drawbacks of a script using nested if/else statements, 4) Identifying if a user entered a digit or letter, 5) Converting between number systems like octal and hexadecimal, 6) Printing a chess board pattern, and 7) Parsing the output of a code sample using a while loop. Students are advised to complete the tasks and assignments in order to be graded on their lab work.

Uploaded by

Aditya Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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