I'm learning to script in bash, trying to solve a little exercise. The exercise is this:
If the variable named "basenew" contains the contents of the variable named "valuebase". "basenew" must contain more than 113,469 characters. If both conditions are met, the script must then print the last 20 characters of the variable "basenew".
My code is
#!/bin/bash
basenew="8dm7KsjU28B7v621Jls"
valuebase="ERmFRMVZ0U2paTlJYTkxDZz09Cg"
for i in {1..40}
do
basenew=$(echo $basenew | base64)
if [[ $basenew =~ $valuebase && ${#basenew} -ge 113469 ]] ; then
echo $i
echo $basenew | wc -c
StrLen=`echo ${basenew} | wc -c`
From=`expr $StrLen - 20`
echo $basenew | cut -c ${From}-${StrLen}
else
echo "error"
fi
done
But I'm stuck, because it prints in the 28th iteration, and it is the 20 last, but it isn't the correct answer.
Any advice to print the last 20 characters using tail -c 20?
Thanks