Saloniyadav OSpracticle File
Saloniyadav OSpracticle File
File
Name-Saloni Yadav
Course-B.A.program(CS +Maths)
Roll No - 2022022
Year - Second
Submission Date - 3 May 2024
CODE-
Code:
cal # shows the current month's calendar
Output:-
Q3. Usage of following commands: chmod, Grep, bc
Code:
Output:-
Code :
formatted_date=$(date i =+%m/%d/%y)
Output:-
Code-
n=3
echo"output"
i=1
while [ $i -le 10 ]
do
echo "$(( n * i))"
i=$(( i+1 ))
done
Output-
Code-
factorial() {
if [ $1 -eq 0 ]; then
echo 1
result=$(factorial $num)
Output:-
Code-
p =6;
do
do
done
done
do
done
echo;
done
Output:-
Code-
a=10
b=20
sum=$(($a+b))#calculate sum
Output:-
Code:-
case $choice in
else
fi
;;
esac
Output:-
10. Write a shell script to find the power of a given number.
Code-
pow()
{ # value of a
a=$1
b=$2
c=1
res=1
if((b==0));
then
res=1
fi
if((a==0));
then
res=1
fi
then
do
res=$((res * a))
c=$((c +1))
done
fi
}
Output:-
Code:-
read -r n
arm=0
tem=$n
r=$((n % 10))
arm=$((arm + r * r* r))
n=$((n / 10))
done
echo $arm
echo "Amstrong"
else
fi
Output:-
gcd() {
local a=$1
local b=$2
local temp=$b
b=$((a % b))
a=$temp
done
echo "$a"
read num1
echo $num1
echo $num2
Output:-
13. Write a shell script to check if the number entered at the
command line is prime or not.
Code:-
is_prime() {
local num=$1
return 1
fi
return 1
fi
done
return 0
read num
echo $num
else
fi
Output:-
Code:-
who_output=$(who)
Output:-
Code-
read -p "enterusername"
if [ $name=$username ]
the
echo "valid"
else
echo "enter loginname is invalid"
fi
Output:-
duplicate file
Code-
file1="Welcome to File1."
file2="Welcome to File2."
read filedelete
else
fi
else
fi
else
fi
Output:-
Q17. Write a shell script to merge the contents Of three sort
the contents and then
Code:
file1="apple
banana
grape"
file2="orange
kiwi
pineapple"
file3="mango
pear
watermelon"
mergecontent=$(echo -e "$file1\n$file2\n$file3")
output:
Q18. Write a shell script to check whether the tile have all
the permissions or not.
Code:
ls –ltr
output:
Q19. Write a shell script to modify "cal" command to
display calendars of the specified
months.
Code:
read month
echo $month
read year
echo $year
exit 1
fi
exit 1
fi
Output:-
Q20. Write a shell script to modify "cal” command to
display calendars of the specified
range of months.
Code:
read startmonth
read endmonth
exit 1
fi
if ! [[ "$endmonth" =~ ^[1-9]|1[0-2]$ ]]; then
exit 1
fi
exit 1
fi
echo "========================"
done
Output:-