[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??

Hey!

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.
-onthesauce

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***==
1 Like

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.
-onthesauce

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.
-onthesace

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.
-onthesauce

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?)

and

$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.

5 Likes

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!

2 Likes

Thank’s.

I spent almost a few hours on this challenge, I understood through your post about the comparisons, thank you very much

You are great, I add for those who are unable to make var > 113450 characters, add in the loop for a variable that takes the characters of var < p=$(echo $var | wc -c) > and insert it in the if after &&. love u.

Hello, I’ve been trying several things but can`t seem to make it right! So the hint os using tail -c 20 is worthless?!?!

Hey, the hint is not worthless. It is essential to getting the answer, what I mention I was hinting at there was that the submission string being output was being muddled by a newline.

What you quoted was just a test for making sure that tail -c 20 actually gave the last 20 characters without a newline. Keep in mind that you could count them manually too. Its been awhile since I have done these challenges, but feel free to DM me and I will help push you along.
-onthesauce

That’s actually how I got my answer.

I’m having a lot of trouble with this one and i’m not sure where i’m going wrong. It seems the script is now just printing all of $var without tail working and even if i count out the last 20 characters manually, the answer is still incorrect.

Same here… I still havent find the solution!