Professional Documents
Culture Documents
Linux
Linux
Write A shell script that takes a command –line argument and reports on whether it is
directry ,a file,or something else
Sol:
2. Write a shell script that accepts a file name starting and ending line numbers as
arguments and displays all the lines between the given line numbers
Sol:
I/P:line1
line2
line3
line4
line5
O/P: line1
line5
3. Write a shell script that computes the gross salary of a employee according to the
following
1) if basic salary is <1500 then HRA 10% of the basic and DA =90% of the basic
2) if basic salary is >1500 then HRA 500 and DA =98% of the basic
The basic salary is entered interactively through the key board
read sal
then
da=$(($sal*90/100 ))
hra=$(($sal*10/100))
gsal=$(($sal+$hra+$da))
then
hra=500
da=$(($sal*98/100))
gsal=$(($sal+$hra+$da))
fi
4. Write a shell script that accepts two integers as its arguments and computes the value
of first number added with the second number
a=$1
b=$2
c=$(($a+$b))
echo$c
x=0
while [ $x -lt 10 ]
do
echo $x
x=$(($x+1))
done
exercise: write a shell script to print the numbers in the above mentioned way where the user can
input the value of x.
10
210
3210
43210
x=0
while [ $x -lt 4 ]
do
y=$x
while [ $y -ge 0 ]
do
echo $y '\c'
y=$(($y-1))
done
echo
x=$(($x+1))
done
exercise: write a shell program to print the output as above but the user will give the value of x.
exercise: write a shell program to print the following outputs
a. *
**
***
****
b. ****
***
**
*
7. Write a shell script that displays a list of all files in the current directory to which the
user has read write and execute permissions
if [ -w $dn/$fn ];then
printf " Write"
fi
if [ -x $dn/$fn ];then
printf " Execute"
fi
printf "\n"
done
else
printf "\n$dn not exists or not a directory"
fi