FAQ: Learn Bash Scripting - Inputs

This community-built FAQ covers the “Inputs” 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 Inputs

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!

How can I try out different ‘greeting_limit’ s?
I totally don’t understand the INPUT lesion. Huhuhu :sob::sob::sob:

11 Likes

This one worked for me

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

echo “How many times should I greet?”
read greeting_limit
while [ $greeting_occasion -lt $greeting_limit ]
do
if [ $greeting_occasion -lt 1 ]
then
echo $first_greeting
else
echo $later_greeting
fi
greeting_occasion=$((greeting_occasion + 1))
done

1 Like

bonjour je n’arrive toujours pas à passer l’étape 2 même en tapant la même chose que toi ?!

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

echo “How many times should I greet?”
read greeting_limit
while [$greeting_occasion -lt$greeting_limit]
do
if [$greeting_occasion -lt1]
then
echo $first_greeting
else
echo later_greeting
fi
greeting_occasion=((greeting_occasion + 1))
done

je ne comprends pas

auriez vous une idée?

s’il vous plait

1 Like

I found:
When you run command line with ./script.sh, it asks you to put a number which will be read as greeting_limit.
If you put a number in command line, it will work.

4 Likes

This lesson is so badly explained…

21 Likes

The first two paragraphs I understand. The rest… what? what is this saycolors bit? And the last bit? Who writes the names of the colors? How do I ask for the input of the colors? is it also with read? Is it with the variable name? What?

8 Likes

HELP

Let’s ask the user how many times the program should greet them.

Just before the while loop, print the following to the terminal: “How many times should I greet?”

Let’s ask the user how many times the program should greet them.

Just before the while loop, print the following to the terminal: “How many times should I greet?”

How do I solve this?

Let’s ask the user how many times the program should greet them.

Just before the while loop, print the following to the terminal: “How many times should I greet?”

what even is greeting_limit? how does the limit part even work?

1 Like

Sorry can someone please help, I put my code as below and always get and error:
Use read to get user input and assign it to the variable greeting_limit . Update the while loop stop condition to be $greeting_limit

My code:
#!/bin/bash
first_greeting=“Nice to meet you!”
later_greeting=“How are you?”
greeting_occasion=0

echo “How many times should I greet?”
read greeting_limt
while [$greeting_occasion -lt $greeting_limit]
do
if [$greeting_occasion -lt 1]
then
echo $first_greeting
else
echo later_greeting fi greeting_occasion=((greeting_occasion + 1))
done

I am pretty sure my code is ok (as per other examples) but cannot figure it out.

sorry I ran your code and it wont work, I get the same error message:

Use read to get user input and assign it to the variable greeting_limit . Update the while loop stop condition to be $greeting_limit

Can you explain that bit? I don’t get how I can “try out different” limits and where in the command line should I insert it?

Hi All,

I think I figured out the last bit for this particular lesson example. Granted it’s not explained clearly what to do in order to “test” greeting_limits, the idea I think is for us to get accustomed to trial and error. The code I have which seems to work is below.

#!/bin/bash
first_greeting=“Nice to meet you!”
later_greeting=“How are you?”
greeting_occasion=0
echo “How many times should I greet?”
read greeting_limit
while [ $greeting_occasion -lt $greeting_limit ]
do
if [ $greeting_occasion -lt 1 ]
then
echo $first_greeting
else
echo later_greeting fi greeting_occasion=((greeting_occasion + 1))
done

When you run the script, you will be prompted the question

$ ./script.sh
How many times should I greet?

You actually need to enter a number into the terminal immediately after this question, then hit enter. When I enter 3 into the terminal, I get the following.

$ ./script.sh
How many times should I greet?
3
Nice to meet you!
How are you?
How are you?

I ran the script again and instead inserted 4 after the question and got the following.

$ ./script.sh
How many times should I greet?
4
Nice to meet you!
How are you?
How are you?
How are you?

I hope this clears everything up. While I do support a trial and error type of learning, I think there should be more clarity for people that are completely new to coding so we’re pushed in the right direction.

All the best!

3 Likes

Try this:

#!/bin/bash
first_greeting=“Nice to meet you!”
later_greeting=“How are you?”
greeting_occasion=0
echo “How many times should I greet?”
read greeting_limit
while [ $greeting_occasion -lt $greeting_limit ]
do
if [ $greeting_occasion -lt 1 ]
then
echo $first_greeting
else
echo $later_greeting
fi
greeting_occasion=$((greeting_occasion + 1))
done

this worked

#!/bin/bash
first_greeting=“Nice to meet you!”
later_greeting=“How are you?”
greeting_occasion=0
echo “How many times should I greet?”
read greeting_limit
while [ $greeting_occasion -lt $greeting_limit ]
do
if [ $greeting_occasion -lt 1 ]
then
echo $first_greeting
else
echo later_greeting fi greeting_occasion=((greeting_occasion + 1))
done

Hi @booga, I have found that rewriting the script removes these errors. I have had similar error issues, where, my code appears to be correct, and it will only work after i re-type it out.

This is only the most important part of bash scripting (importing data). Hope they fix eventually after reading these comments.

3 Likes

Just awful. Even more awful than the previous lesson.

1 Like