FAQ: Learn Bash Scripting - Variables

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

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!

I really struggled to understand what I was meant to typing where with the two boxes open.
Even following the hints the green ticks didn’t come up.

2 Likes

…because you have to press run in the script first…couldn’t see that instruction any where…

2 Likes

Agree, not user friendly at all

What does “#!/bin/bash” mean or do in the script.sh?

the #/bin/bash command tells the computer which interpreter to use when reading the script.

Thank you! Could not get the “Hello Codecademy” to go away even though I had all green check marks and had edited the text correctly.

What’s also not clear is how to run the file and what output you should expect. When I use ‘chmod +x ./script.sh’ nothing happens. When I use source ./script.sh it outputs the string to the terminal

1 Like

Why do we need to use the ‘$’ symbol before the variable name?

Why do we have to run the script like ‘./script.sh’ why can’t we simply type ‘script.sh’

A $ symbol is for using the value stored within a particular variable. If you just used the name in this case echo phrase it would just print that out phrase. echo $phrase prints the value stored by that variable to the screen.

Without those additions you’d be looking for a command with that name on the path (which is not what you want). Using the absolute path (or part of it, in this case . is the current directory) lets the script be run.

2 Likes

It’s interesting that echo “$phrase” isn’t accepted… even though it is probably better practice to invoke variables with soft-quotes.

Because that would echo the literal phrase $phrase to the console (i.e you run the script and the console prints out $phrase). That wouldn’t be a better practice because it just makes it more difficult to echo strings with a dollar sign in it, and makes it harder to understand what is a literal string and what is a variable