I started learning bash scripting and was given the task of making the code below print the count of letters for the 35th encoding with if-else statements.
#!/bin/bash
# Variable to encode
var="nef892na9s1p9asn2aJs71nIsm"
for counter in {1..40}
do
var=$(echo $var | base64)
done
I came up with :
#!/bin/bash
# Count number of characters in a variable:
#echo $variable | wc -c
# Variable to encode
var="nef892na9s1p9asn2aJs71nIsm"
i=0
for counter in {1..40}
do
var=$(echo $var | base64)
((i=i+1))
if [[$i == '35']]
then
echo $var | wc -c
fi
done
but I always get an error at if [[$i == ’35’]] saying command not found
>Solution :
You must have space after [[ and before ]] otherwise it will be taken as command.
The correct code should be : [[ $i == ’35’ ]]