FAQ: Learn Bash Scripting - Conditionals


#1

This community-built FAQ covers the “Conditionals” exercise from the lesson “Learn Bash Scripting”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn the Command Line

FAQs on the exercise Conditionals

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

Hey!
I wonder why in in stage 3 “Conditionals” there is “greeting_number=0” prewritten in script.sh, yet in our conditional we are supposed to write “greeting_ocasion”. When I executed the file with “greeting_ocasion” there was an error.
Here is the code that is written by instructions and does not work properly:

#!/bin/bash
first_greeting=“Nice to meet you!”
later_greeting=“How are you?”
greeting_number=1

if [ $greeting_occasion -lt 1 ]
then
echo $first_greeting
else
echo $later_greeting
fi

When script is executed in bash it displays “./script.sh: line 7: [: -lt: unary operator expected”

And here that works but is not written as asked:

#!/bin/bash
first_greeting=“Nice to meet you!”
later_greeting=“How are you?”
greeting_number=1

if [ $greeting_number -lt 1 ]
then
echo $first_greeting
else
echo $later_greeting
fi

Am I thinking wrong? If yes, please explain.

Cheers!
Simon


#3

Yeah, this same thing happened to me. What’s going on?


#4

This is a mistype, _number instead of _occasion. I took my hint from the error message, changed it and passed. Be sure to submit a bug report pointing out this glitch.