In: Computer Science
3. Write a script that generates two random numbers between -5 and 25, calculates their average, and if the average is greater than 10 then prints “High Average” else prints “Low Average”. You can use $RANDOM to generate the random numbers.
4. Write a script using the for-loop construct that counts the number of directories looping through the files in the directory name provided by the user on a prompt by the script.
Answer 3
*************
#!/bin/bash
for (( i=1;i<=5;i++ ))
do
number=`seq -5 25 | sort -R | head -n 1`
array+=("$number")
echo $number
done
avg()
{
for n in ${array[@]}
do
(( total += n ))
done
echo "Total is: "$total
avg=`echo "$total / 5" | bc -l`
echo "Average is: "$avg
}
avg
Answer 4
***********
#!/bin/bash
OLD_IFS="$IFS"
IFS=$'\n'
echo "Enter Directory name: "
read fn
for dir in $(find $fn -maxdepth 1 -type d | sort);
do
files=("$dir"/*)
printf "%5d,%s\n" "${#files[@]}" "$dir"
done
FS="$OLD_IFS"
if you have any doubt then please ask me without any hesitation
in the comment section below , if you like my answer then please
thumbs up for the answer , before giving thumbs down please discuss
the question it may possible that we may understand the question
different way and we can edit and change the answers if you argue,
thanks :)