FAQ: Learn Bash Scripting - Loops

I spend hour understanding what was wrong. I has error on line 5, and adding space:
while [ $greeting_occasion -lt 3 ] #working
while [ $greeting_occasion -lt 3] #notWorking
Hope I help somebody!)

Can´t understand this part of the code: index=$((index + 1))

It’s effectively adding 1 to the value named with index. Additional brackets are for ‘arithmetic expansion’: https://wiki.bash-hackers.org/syntax/expansion/arith


Thanks!! Loops really confuse me :woozy_face:

Just a heads up to those struggling (and maybe the creators if they are scanning this?) the step 1 to add the start of the ‘while’ loop will accept it even if it is missing a space before the closing square bracket, but this will not run past the second step.

while [ $greeting_occasion -lt 3 ] <---- make sure there is a space after the 3.

1 Like

I couldn’t have said it better myself so I’ll just like your post instead of borderline spamming the same sentiments everyone has brought up. It’s a shame because I actually think the course was solid up until the last section for bash scripting. I reset the lesson and project because it just didn’t feel right getting that completion certificate without actually understanding any of it (I know it holds no weight in the real world but it just feels odd showing I completed the last section)

The Bash Scripting unit in the course does contain some content that would be more understandable with basic programming knowledge.

I recommend you take one of the programming language courses here on Codecademy (you can find the catalogue here) and come back to this unit afterwards. Things you should learn about include variables, conditionals, loops, and potentially functions/methods (different names depending on the programming language) as well.

1 Like