Documente Academic
Documente Profesional
Documente Cultură
sh command at terminal)
Running Environment - LinuxMint
1. Write shell script using for loop to print the following patterns on screen
2. Write shell script using for loop to print the following patterns on screen
for (( i=1; i<=5; i++ ))
do
for (( j=1; j<=i; j++ ))
do
echo -n "$j"
done
echo ""
done
3. Write shell script using for loop to print the following patterns on screen
n=0
on=0
fact=1
on=$n
while [ $n -ge 1 ]
do
fact=`expr $fact \* $n`
n=`expr $n - 1`
done
5. Write a Shell Script to find "a" to the power "b" using Function.
while((c>0))
do
a=$((c%10))
b=$((b + a*a*a))
c=$((c/10))
done
if((b==d)); then
echo "$i"
fi
i=$((i+1))
done
for((i=0;i<5;i++))
do
echo "enter `expr $i + 1` number"
read arr[$i]
done
echo "the numbers you have entered are"
for((i=0;i<5;i++))
do
echo ${arr[$i]}
done
8. Write a Shell Script to add two numbers using Function.
add()
{
x=$1
y=$2
echo -e "Number entered by u are: $x and $y"
echo "sum of $1 and $2 is `expr $x + $y` "
}
a=$((a+b))
b=$((a-b))
a=$((a-b))
echo "a after swapping is $a and b is $b"
for((i=1;i<n;i++))
do
j=$i-1
temp=${arr[$i]}
while((j>=0 && arr[j]>temp))
do
arr[$j+1]=${arr[$j]}
j=$j-1
done
arr[j+1]=$temp
done
c=0
a=1
b=1
read -p "Enter limit of fibonacci Series:" n
echo -n "$a "
echo -n "$b "
while((c<n))
do
c=$((a+b))
echo -n "$c "
a=$b
b=$c
done
15. Write a Shell Script to check whether a given String is Palindrome or not.