Hello all,
I currently having issues with the first task of Introduction to Bash Scripting on the HTB Academy platform.
Here is the code in question:
#!/bin/bash
# Count number of characters in a variable:
# echo $variable | wc -c
# Variable to encode
var="nef892na9s1p9asn2aJs71nIsm"
for counter in {1..40}
do
var=$(echo $var | base64)
done
The question is " Create an “If-Else” condition in the “For”-Loop of the “Exercise Script” that prints you the number of characters of the 35th generated value of the variable “var”. Submit the number as the answer."
I tried many different approaches but keep getting the wrong answers. Can someone nudge me on the right direction?
Here is my code:
#!/bin/bash
# Variable to encode
var="nef892na9s1p9asn2aJs71nIsm"
for counter in {1..40}
do
var=$(echo -n $var | base64 -w 0)
if [ $counter -eq 35 ]; then
num_chars=${#var}
echo "Number of characters in the 35th encoded value: $num_chars"
fi
done
Thanks in Advance.