top of page

UNIX Shell Script Help

Updated: Mar 18, 2021


Ques 1:

Write shell script for the following

It should display menu for following

Display file contents with line number

display the file contents with page break

quit.


Answer:



echo "\n Enter your choice
            \n1)show file content with line number
            2) show file content with pagebreak\n
            3)quit"
read choice
case "$choice" in
            1)echo "enter the file name";read fname;cat -b $fname;;
            2)echo "enter the file name";read fname;cat  $fname | more;;
            3)exit
esac
 

Quest 2:

Write a shell script for accepting the following information and storing in file.

i) customer name

ii) item description

iii) quantity

iv) rate the user should get the facility to enter as many record as he wants.

Answer:


ans=y
echo "enter the file name:\c"
read fname
while [ "$ans" = "y" ]
do
echo  "Enter\n customer name  |item description| quantity| rate:\c" >/dev/tty
read cname itemd quant rate
echo "$cname|$itemd|$quant|rate" >> $fname
echo "record inserted successfully:\c"
echo "do you want to continue:(y/n)"
read c
case "$c" in
            y*|Y*) ans=y;;
            n*|N*) ans=n;;
            *) ans=y ;;
esac
done




bottom of page