i need help with shell bash. I'm running it on ubuntu virtual machine My task is this # A three-digit number is given. Calculate the value of the second digit in the number. # For example, = 456 → = 5.
Here is what i have so far
read -r -p "enter the number" num
while (( $num > 0 )) ; do
digit = "$((num % 10))"
num ="$(( num / 10 ))"
printf "num=%d digit=%d\n" "${num}" "${digit}"
done
Please tell me how i should expand my code so that it actually works , By the way the task is to calculate the digit with loops So doing it this way is no good even though its easier
read -r -p "enter the number: " num
printf "%s\n" "${num:1:1}"