update unix program bca6th sem
update unix program bca6th sem
2. # Linux shell script program to create and print the value of variables.
country="India"
year=2021
echo "Country name: $country"
echo "Year: $year"
7.# shell script program to add two numbers using command line arguments.
sum=`expr $1 + $2`
echo "Sum is: $sum"
12. # Shell Program to print swap two Numbers using 3rd variable
clear
echo "Enter first number: "
read a
echo "Enter second number: "
read b
c=$a
a=$b
b=$c
if [ $a == $b ]
then
echo "a is equal to b"
else
echo "a is not equal to b"
fi
16 #Write a Shell Script to take integer value from user and print some message based on a match
echo "Enter number:"
read num
case $num in
1)
echo "It's one!"
;;
2)
echo "It's two!"
;;
3)
echo "It's three!"
;;
*)
echo "It's something else!"
;;
esac
17 #In the following example we will take user name and time of the day as input and display
some greetings message.
"Afternoon")
echo "Good Afternoon $name"
;;
"Evening")
echo "Good Evening $name"
;;
"Night")
echo "Good Night $name"
;;
esac
18 #In the following example we will take two integer numbers from the user and divide them and
show 5 decimal place.
3. INPUT_STRING=hello
while [ "$INPUT_STRING" != "bye" ]
do
echo "Please type something in (bye to quit)"
read INPUT_STRING
echo "You typed: $INPUT_STRING"
done
4. while :
do
echo "Please type something in (^C to quit)"
read INPUT_STRING
echo "You typed: $INPUT_STRING"
done
6. for var in 0 1 2 3 4 5 6 7 8 9
do
echo $var
done
7. a=0
while [ "$a" -lt 10 ] # this is loop1
do
b="$a"
while [ "$b" -ge 0 ] # this is loop2
do
echo -n "$b "
b=`expr $b - 1`
done
echo
a=`expr $a + 1`
done
8. a=10
until [ $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
9. a=0
while [ $a -lt 10 ]
do
echo $a
if [ $a -eq 5 ]
then
break
fi
a=`expr $a + 1`
done
10.
NUMS="1 2 3 4 5 6 7"
for NUM in $NUMS
do
Q=`expr $NUM % 2`
if [ $Q -eq 0 ]
then
echo "Number is an even number!!"
continue
fi
echo "Found odd number"
done