FAQ: Learn Bash Scripting - Review

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

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!

The BASH CLI course is far too narrow and, AFAIC, incomplete.


It really seems like this Bash Scripting course stops short. Can somebody tell me about, for example, functions?

I’ve done some research, but I can’t get my function to return anything. When I call the function, instead of returning a number, it apparently returns the name of the function.

Here’s my code:


get_number() {
	return 6

echo $boolean_number

Out of the code above, all I get in the terminal window is get_number

Can someone help me, please?


That’s not the name of the function, that’s just text which happens to be the same characters as the name of the function. You’d need to evaluate that expression to obtain its result.

You might also want to write the result of your function to stdout rather than setting an exit value.

1 Like

Well, how do I properly call the boolean_number function and assign it’s return value to the boolean_number variable?

Also, can you confirm that I don’t have any syntax errors in my function?

1 Like

You…don’t. They’re not conventional functions. They’re more like programs.
If you wanted such behaviour you should likely be looking for something like perl/python/ruby/whatever.

bash isn’t a programming language as much as it is just glue between other programs
You can certainly encode logic with it but err. Yeah. That’s not quite what it is.

1 Like

So, the first thing to note is that your expectations don’t apply.

But you can get similar behaviour. Like mentioned, you’d probably print the result instead. You can also set a variable which the caller can look at afterwards.

add() {
    echo "$1 + $2" | bc

echo $(add 1 2)

add() {
    returnvalue=$(echo "$1 + $2" | bc)

add 1 2
echo $returnvalue
unset returnvalue

Oh and getting quoting right is a bit of a nightmare so, again, you might want to prefer to just not, and instead use some… uh. you know. programming language.


Oh. Okay. That’s too bad


Hello to everyone!

Could someone please be so kind as to explain some things to me?

So far I had no trouble understanding other lessons but this one in particular I cant understand. For example I don’t understand the meaning behind this part of code “index=$((index + 1))”…why do we write that, what is its purpose, why “+1”…Other lessons breakdown each command word by word and explain what each word does basically, what is the logic behind it. Here I have no clue what this means and what is its purpose. As a result, I do not understand the result that is produced from the code we build in this chapter.

while [ $greeting_occasion -lt 3 ]
if [ $greeting_occasion -lt 1 ]
echo $first_greeting
echo later_greeting fi greeting_occasion=((greeting_occasion + 1))

Why does it produce just 2 “How are you?” statements if this is a loop? the variable does not change (remains equal to 1). If I am not mistaken the while loop basically loops the same output over and over again as long as the variable meets a certain condition.

Then we go to Inputs…here I cant even begin to understand what I want to ask…The exercise tells us to get user input and assign it to the variable greeting_limit…and replace the number 3 with that variable(prepended $)…is ‘read’ adopting whatever ‘echo’ follows? I am lost…

Please if someone could shed some light for this particular last chapter(5) of Learn command Line… I wish I could ask better questions but I am too confused. And again this is the first time I felt this way into a lesson.

Thank you in advance!


I agree. The course was great, and provided explanations for each command as well as how it might be useful when coding IRL. But this Bash section just confused me, and I can honestly say that I have no idea why I did what I did, what the purpose of the commands is exactly IRL, and how input arguments, aliases, conditionals, loops, or anything else in this section, fits together. This was horrible. And it began at the beginning with the first command: #!/bin/bash (pray tell what does the “#” do, or even the “!”). This was frustrating, and not at all worthy of being approved for beginners.


Glad to see I am not the only one who struggled with this…I was so frustrated and was starting to believe I am a dummy hahaha

1 Like

Just had the exact same thoughts. Spent a few days working through the course and understanding it all more or less, but the bash scripting section referenced so many things without telling us what they are, what they mean or why they did them. Suddenly felt like I skipped ahead 10 lessons.



Okay, so I have a couple of questions regarding the purpose of bash scripts. The tutorial states that all code that can be run in terminal can also be run using a bash script, so I don’t quite get why they need both… What do bash scripts have that terminal doesn’t have?

Also, there seems to be some connection between bash scripts and the ./bash_profile that I don’t understand… Is this correct or am I overinterpreting?

Lastly, could someone please explain to me what the purpose of the read command is (btw, if there is an acknowledged guide explaining all of the function, it would be awesome if you could share that). It says in the tutorials that it “prompts the used for input in order to access data external to the bash script file itself”. - I do not understand what that means. Below is the example that they gave in the exercise:

echo “Guess a number”
read number
echo “You guessed $number”

Thanks in advance

A script is code stored in a file for later use.
If you just want to fire off some one-off commands then you’d have no reason to store the commands in a file.
On some systems bash is analogous to your mouse pointer, it is how the computer is interacted with. For some systems there isn’t even a choice, they aren’t plugged to a monitor and therefore don’t draw pretty pictures for anyone to click on.

Many programs come with manuals, if you run

$ man read

On a system that has both man and manpages installed then you’ll find a description on what it does…You can also google for that manpage.

.bash_profile and .bashrc can be used to run commands every time bash is started, think of it as settings, except there are no settings, instead you run commands to modify the environment to your liking.

bash’s man page has information about them.

$ man bash

What would be really helpful is if someone could post the code for the three ideas suggested in the exercise to help with our learning:

"Some ideas:

** ask the user for different greetings*
** add more than two greetings*
** add more conditions to adjust the greetings over time*"



Echoing the sentiment from others on this lesson. Extremely confusing with very little real-world examples of applications. Anyone can follow the instructions in this, but it seems the “WHY” is missing entirely. I worked through the entire thing and have read all of these comments – still no idea why I’d create bash scripts for, say, building a SaaS application.


I too had a problem with this code and mine looks the same as yours but it keeps telling me im wrong. These instructions are deeply flawed

1 Like

if you been into while loops in other programming languages so far , basically it’s just needed to determinate when the loop has to stop .
If you look at the while loop condition you wrote $greeting_occasion -lt 3 , the while will keep running till greeting_occasion reaches the value of 3 , which you are incrementing by 1 at the bottom of the loop ( greeting_occasion=((greeting_occasion + 1)) ).

That’s cause you have a syntax error , it should be greeting_occasion=$((greeting_occasion + 1))

you forgot the “$”.

Was just “awarded” the Badge for “learning” Bash Scripting, and reader, let me tell you that this is the first badge I feel like I should send back, lol. This was terrible. I’m a big believer in absorbing concepts properly before moving on to the next, but I feel like I’m in quicksand here, and I’ll be stuck here forever unless I just move on and hope for the best.
On to Python, and leave this mess behind. I paid good money for Codecademy Pro but I think I’m going to go to another source to properly learn bash scripting so it doesn’t completely undermine me while learning Python.
What a chore this was. Scrap it and start over.


This would be highly appreciated @ionatan and any other person that understands what we need to do

1 Like