Introduction to Bash Scripting - Conditional and Comparison

Hi!

I did bash script to both exercises (Conditionals and Comparison) but ain’t getting the right results. May anyone help me finding the right answer?

[Conditional Exercise]

#!/bin/bash

var=“nef892na9s1p9asn2aJs71nIsm”

for counter in {1…40}
do
var=$(echo $var | base64)
((counter += 1))
if [ $counter -le 35 ]
then

    echo $var | wc -c

fi
done

[Comparison Exercise]

#!/bin/bash

var=“8dm7KsjU28B7v621Jls”
value=“ERmFRMVZ0U2paTlJYTkxDZz09Cg”

for i in {1…40}
do
var=$(echo “$var” | base64)
((i+=1))
if [[ “$var” == “$value” ]] && (( ${#var} > 113450 ))
then
echo “The last 20 characters of var are: ${var: -20}.”
else
echo “Variables does not meet both conditions.”
fi
done

Thanks

Hello! I`m working on it right now! If I happen to solve it I will let you know.

1 Like

Here are two very helpful resources that everyone should probably have.

Pattern Matching: regex - Pattern matching in if statement in bash - Stack Overflow

Operations on Variables: Operations on variables

Thanks in advance