It-853: Linux Administration and Programming Lab List of Practicals
It-853: Linux Administration and Programming Lab List of Practicals
LIST OF PRACTICALS
1.
Write a shell script that reads a number and prints it in reverse order.
#!/bin/bash
read num
rev=0
while [ $num -gt 0 ]
do
rev=`expr $rev \* 10`
tmp=`expr $num % 10`
rev=`expr $rev + $tmp`
num=`expr $num / 10`
done
echo $rev
4. Write a shell script that waits for a user to log into the system.
#!/bin/bash
echo "Lines containg $1"
grep $1 $2
echo "Lines not contaning $1"
grep -v $1 $2
wc -l $2
echo "lines are there in $2"
6. Write a shell script that accepts a signal number and process id as its arguments, and sends
7. Write a shell script that makes bash script files in the currently working directory
executable, if they are not.
#!/bin/bash/
for file in *
do
ext="${file##*.}"
if [ -f $file -a $ext=="bash" -a ! -x $file ]
then
chmod +x $file
ls -l $file
fi
done
8. Write a shell script that finds the biggest of all the positive numbers supplied by the user.
#!/bin/bash/
max=-99999
read -a arr
for i in ${arr[@]}
do
if [ $max -lt $i ]
then
max=$i
fi
done
echo $max
15. Write a shell script that prints the output in following pattern:
1
12
123
1234
12345
Take the number of lines as input.
#!/bin/bash/
i=1
echo "Enter number of lines"
read lines
while [ $i -le $lines ]
do
j=1
while [ $j -le $i ]
do
echo -n $j " "
j=`expr $j + 1`
done
i=`expr $i + 1`
echo ""
done