Bourne Shell Hands-Ons [Unix > Bourne Shell] | Accenture TFA Training Pre-Learning Modules
Disclaimer: The primary purpose of providing this solution is to assist and support anyone who are unable to complete these courses due to a technical issue or a lack of expertise. This website's information or data are solely for the purpose of knowledge and education.
Make an effort to understand these solutions and apply them to your Hands-On difficulties. (It is not advisable that copy and paste these solutions).
All Question of the Hands-On Present Below for Ease Use Ctrl + F with the question name to find the Question. All the Best!
1. Script to Change Permission
Path: UNIX/Bourne Shell/Script to Change Permission/script3.sh
for f in ${*}
do
if [ -e $f ]; then
echo "File Exists!"
if [ -w $f ] && [ -r $f ]; then
chmod a=rwx $f && echo "File Permission has been changed"
fi
else
echo "File does not Exist" && exit
fi
done
2. Script tp Check Permission
Path: UNIX/Bourne Shell/Script to Check Permission/script2.sh
for f in ${*}
do
[ -w $f ] && W="Write : yes" || W="Write : no"
[ -x $f ] && X="Execute : yes" || X="Execute : no"
[ -r $f ] && R="Read : yes" || R="Read : no"
[ -d $f ] && D="Directory : yes" || D="Directory : no"
echo "$W"
echo "$R"
echo "$X"
echo "$D"
done
3. Script to Count
Path: UNIX/Bourne Shell/Script to Count/script1.sh
for F in ${*}
do
echo
c=$( wc -c < ${F})
echo "Number of characters in ${F} is $c"
echo
w=$( wc -w < ${F} )
echo "Number of words in ${F} is $w"
echo
l=$( wc -l < ${F})
echo "Number of lines in ${F} is $l"
done
4. ShellScipt1
Path: UNIX/Bourne Shell/ShellScript1/scriptprog1.sh
read -p "" num1
read -p "" num2
sum=$(($num1+ $num2))
echo "Sum of $num1 and $num2 is $sum"
5. ShellScript2
Path: UNIX/Bourne Shell/ShellScript2/scriptprog2.sh
read a
read b
read c
if [ $a -eq $b -a $a -eq $c ]; then
echo "All the three numbers are equal"
elif [[ $a -eq $b || $b -eq $c || $c -eq $a ]]; then
echo "I cannot figure out which number is largest"
else
if [ $a -gt $b -a $a -gt $c ]; then
echo "$a is largest number"
elif [ $b -gt $a -a $b -gt $c ]; then
echo "$b is largest number"
elif [ $c -gt $a -a $c -gt $b ]; then
echo "$c is largest number"
fi
fi
6. ShellScript3
Path: UNIX/Bourne Shell/Shellscript3/scriptprog3.sh
#!/bin/bash
for number in 5 4 3 2 1
do
echo $number
done
exit 0
7. ShellScript4
Path: UNIX/Bourne Shell/ShellScript4/scriptprog4.sh
read n
sd=0
rev=0
if [ $n -lt 0 ]
then echo "Not a positive number"
exit
fi
while [[ $n -gt 0 ]]
do
sd=$(( $n%10 ))
rev=$(( $rev*10 + $sd ))
n=$(( $n/10 ))
done
echo "Reverse number is $rev"
8. Shellscript5
Path: UNIX/Bourne Shell/Shellscript5/scriptprog5.sh
read a
s=0
if [ $a -lt 0 ]
then
echo "Not a positive number"
else
while [[ $a -gt 0 ]]
do
k=$(( $a % 10 ))
a=$(( $a / 10 ))
s=$(( $k + $s ))
done
echo "Sum of digit for given number is $s"
fi
If you have any queries, please feel free to ask on the comment section.If you want MCQs and Hands-On solutions for any courses, Please feel free to ask on the comment section too.Please share and support our page!
Post a Comment