FAQ: Learn Bash Scripting - Introduction to Bash Scripting

This community-built FAQ covers the “Introduction to Bash Scripting” 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 Introduction to Bash Scripting

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!

Step 3. requires us to use ./script.sh to run the script in the terminal.
I think I missed a crucial piece of information because I don’t remember that command being taught before.
I actually had to look at the hint to figure out what I was expected to do.
In my opinion, looking at the hints should be a last resource sort of thing, not the go-to place to receive the information that’s needed in order to complete a lesson. What am I missing here? I even checked very own list of commands and couldn’t find it there. :sweat_smile:

12 Likes

You just wrote that command, it is the path of your file, there’s nothing else going on there, not a single character

I am sorry, could you elaborate a little bit? I’m completely new to everything related to programming and just started with Codecademy about 9 days ago. Is ./script.sh not a command? Am I not commanding the CLI to run a script? Does writing the path of a file automatically run it in Bash?

It’s not automatic if you tell it. But other than that, yes, most commands are files by those names. Regular programs.

This particular lesson was extremely frustrating.

It didn’t explain the differences between the script.sh window or the bash window. There’s an entire section of the lesson explaining a chmod command that doesn’t actually get addressed or explained.

I also don’t understand why you need to type ./script.sh as opposed to just script.sh
What is the difference?

12 Likes

Question regarding that exercise:

Is it the same when I:

1: add -echo “Hello”- in the bash_profile
and
2: write a script like “./script.sh” with the -echo “Hello”- and run it on the terminal
?

I’m a newbie so I might not be completely accurate but I think I have the gist of it.
The script.sh command that you make in this part is saved in the “/home/ccuser/workspace/learn-bash-scripting-introduction” directory and you can see it with “pwd” in the command line tab. If you also use “ls” you can see that the file called “script.sh” is in it, which contains your custom command.
Something that isn’t clear in the course (or I just didn’t notice) is that “./” is your current directory and “…/” is its parent directory (the one it belongs to)
So essentially by writing “./script.sh” you “show” the command line that file and “tell” it to run it.
For the same reason if you left that directory ("/home/ccuser/workspace/learn-bash-scripting-introduction") you wouldn’t be able to use “./script.sh” and you would have to specify the directory by writing “/home/ccuser/workspace/learn-bash-scripting-introduction/script.sh” or some other variation of that line that “points” to the same file.
As for the other commands that work without writing the full directory (like “pwd” or “ls”) I’m not sure. It might have to do with the fact that they are saved in a directory that belongs to PATH or they might have an alias so you don’t have to write the full directory every time, but I’m certain there are ways to write commands that work like that (just by name)
Hope that helps.

8 Likes

SOS nothing happens on Terminal - what have to be put in Terminal ???

1 Like

Totally agree - TOTALLY FRUSTRATING

3 Likes

This lesson gives the file name of the file that is opened to load the configuration on two different platforms:
Linux ~/.bashrc
OSX ~/.bash_profile
What about windows running git bash?

1 Like

Windows doesn’t work with git bash. it has it’s own command line interface. when i started this course there was a video about it but a can"t find it back

When I run ./script.sh nothing happens… shouldn’t the bash terminal out “Hello Codecademy!” because the echo command is in my script? Am I running the script incorrectly?

My Script:

#!/bin/bash
echo “Hello Codecademy!”

My Bash Terminal:

./script.sh

I was having trouble in this step but then figured out that I needed to run the ./script.sh in the bash terminal. Some lessons do not explain well enough. It feels like we are missing info.

3 Likes

Can’t go past the #!/bin/bash step. Tells me to type exactly that but won’t respond. Anyone with the same problem?

2 Likes

Is there something wrong here? Or this is the expected output?
There is really nothing in the tutorial mentioning this error and I am following all the steps…

1 Like

im getting the same error. I think it’s something with the actual bash interpreter? way above my head for a beginner, lol.

I found out the fix!!

in the script.sh, add this line to the top:

set ff=unix

apparently the text editor is saving it as DOS format, and not unix? No idea why.

4 Likes

Thanks! it works! it’s really strange, the whole Command line section is quite badly-designed and confusing. You need some external information to understand the concept…

1 Like

You also might need to do this on the next exercise:

Using sed Command

Remove the spurious CR characters. You can do it with the following command:

sed -i -e 's/\r$//' NAME-OF-FILE.sh

as when you edit and save it’ll keep saving in extra unwanted characters in the .sh file.

From this page