Hello im learning to script in bash, i 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
var="8dm7KsjU28B7v621Jls"
value="ERmFRMVZ0U2paTlJYTkxDZz09Cg"
for i in {1..40}
do
var=$(echo $var | base64)
if [[ $var =~ $value && ${#var} -ge 113469 ]] ; then
echo $i
echo $var | wc -c
StrLen=`echo ${var} | wc -c`
From=`expr $StrLen - 20`
echo $var | cut -c ${From}-${StrLen}
else
echo "error"
fi
done
But im stuck, because prints in the loop 28, and are the 20 last but isn't the correct answer.
Any advice to print the last 20 characters using tail -c 20?
Thanks
Aucun commentaire:
Enregistrer un commentaire