[Introduction to Bash Scripting][Comparison Operators]

hey guys.i found the answer of
"+ 3 Create an “If-Else” condition in the “For”-Loop that checks if the variable named “var” contains the contents of the variable named “value”. Additionally, the variable “var” must contain more than 113,469 characters. If these conditions are met, the script must then print the last 20 characters of the variable “var”. Submit these last 20 characters as the answer.’
question but it didnt accept that.how can we report this to hack the box??


There isn’t any bug that I can see. I just wrote a script and got the answer. Although the wording of the question seems to be a bit misleading.

Run it again, copy and paste your answer into the following echo "submissionstring" | wc -c to make sure it is actually 20.

You might want to fiddle with the echo command you are using to get the last 20. I think you will find your issue is there.

DM me if you run into any trouble.

that was my problem.i found it.thanks

The character count of the answer is actually 19. :sweat_smile:

echo "${var: -19}" 
# will result in the correct answer: ***TlJY***DZz0***==

When you count them out it is. But maybe 20 with the \n?

I like the way you got it though. I think in admiralhr99’s case he was using the -n flag with echo and it was throwing the string off.

Hey. I am stuck at the “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.” question from Conditional Execution.
I have tried to use wc -c and ${#var} but the number (800980) is still wont be the wanted answer. Can you give me a hand for this question?

Hey @wtjsk, I definitely can help you out.

DM me the script you are trying to use and I will help you debug it.

I have solved this question, but I want to figure out where the -n flag is substituted in echo?
What is he doing?
The script also gave me an answer in the form of 19))
I want to fully understand this issue.
I will be grateful for an explanation.

No worries, I suggest booting up a pwnbox and testing the following. It should help you understand it better.
echo automatically appends a \n to each output. So as an example try this:
echo hello | wc -c
echo -n hello | wc -c

Now lets say that the flag was the lo and you needed to retrieve it via tail -c 2
Try this:
echo hello | tail -c
echo -n hello | tail -c

This should display how big a difference the -n flag can make. Remember this for future modules when you need to use echo string | base64 to encode a payload. If you don’t have the -n then it could throw off the whole payload, echo -n string | base64 will give different output then the previous command.

1 Like

Wow, super!
Thanks for the analysis!

I am a bit confused on this one. It seems I have to do -gt 113468 or -eq 113469 to get the correct answer (I didn’t think I should paste my whole script in here for spoilers).

The question says “Additionally, the variable “var” must contain more than 113,469 characters.”
so I would think it should be -gt 113469

I was able to get the answer, but I am not sure I understand why.

@CrazyHorse302 dont forget about the ‘-ge’ operator which is “greater than or equal to”

Also, in general, this lab got me PISSED…

apparently there’s two labs, one that says
iterate thru 35 loops then...
and then there’s the one that i got which was
find the encoded variable containing $value w/ chars > 113470

so what is so aggravating about this lab is they go into ZERO DETAIL about how to do substring finding… i was trying to $(echo $var | grep $value)… and that apparently wasnt working they way i was doing it… took the SAME EXACT STRUCTURE and used the following two ACTUAL SUBSTRING BUILT-INs and i solved the lab immediatley… so please be aware of them and use them…

$var =~ "$value" (regex, apparently?)


$var == *"$value"* (wildcard, substring)

this should help tremendously for those who are struggling for HOURS like i did… this lab needs revision to discuss either how to use grep to find the answer (since its already mentioned previously in the lab) OR how to use the above substrings… i wish i could see what the authors suggested answer is as i would be very curious to know.


My 2 hints are:

The first thing it asks you for is, are var and variable the same? == does not work for this. Read the following article to find out what does:
What’s the difference between “==” and “=~”?

The second thing it asks for is to find the character count of var. Read here to find out how to do so:
How can I count the number of characters in a Bash variable

Most people really struggle with this one, so don’t give up!! If it takes you a while to figure this out, it doesn’t mean you’re not smart, it means you are normal and like most people!
Feel free to message me with questions!