FAQ: Learn Bash Scripting - Review

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.

10 Likes

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.

2 Likes

Hi

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
2 Likes

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*"

Thanks

2 Likes

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.

2 Likes

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.

3 Likes

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

1 Like

Feels like codecademy have just given up on this course. Shame because I find the other courses really useful.

1 Like

I just finished this module as part of the web dev path. Since I am a windows-user I don’t really interact with my computers through the command line. I think that is what Bash does. But I’m not entirely sure. Given from what I’ve seen so far, I think Bash might be needed once Node.js comes into the picture. Maybe.

Someone here described the module feeling like quicksand and yes, I think that’s correct. Reading that I am certainly not the only one left completely bewildered after doing this module, I’m just going to leave it for now. Module finished, badge earnt, let’s see if the knowledge will ever pop up as necessary in a different module.

2 Likes

I did enjoy the course very much however, I think the projects particularly in bash scripting should have been geared up towards real-live job scenario simulation. For example, how to write script to monitor system"hardware" or “memory”. Even better how to create New Departments with number of Users including key use within each department. I think this could be achieved within diving deep into the commands.

Notwithstanding, I my immense gratitude for the course and the content and am happy to contribute in coming up with ideas to challenge student who want to learn.

Why can’t I get the if elif else statement to run in a while loop?
Finished the exercise and was trying to get a multiple option to work in a loop

#!/bin/bash
first_greeting=“Nice to meet you!”
later_greeting=“How are you?”
last_greeting=“Don’t ask again”
greeting_occasion=0
greeting_limit=$1
echo “pick a number”
read greeting_limit
while [ $greeting_occasion -lt $greeting_limit ]
do
if [ $greeting_occasion -lt 1 ]
then
echo $first_greeting
else
if [ $greeting_occasion == $greeting_limit -1 ]
then
echo $last_greeting
else
echo last_greeting fi fi greeting_occasion=((greeting_occasion + 1))
done

Hello @nedescon!

Please format your code according to this topic.

You seem to be missing fi statements, which should go at the end of a conditional.

Example
if [ 5 -lt 10 ]
then
  echo 5 is less than 10
else
  echo 5 is not less than 10
fi

I believe you need to put a $ before last_greeting in the second to last line. I also believe you mean to write later_greeting here.

Secondly, I believe if you would like to use arithmetic here:

Then you must format it like this:

if [ $greeting_occasion == $((greeting_limit - 1)) ]

Although I am not sure as I haven’t used the logical operator yet. There’s another way to structure this loop structure like this:

while [ $greeting_occasion -le $greeting_limit ]
do
  if [ $greeting_occasion -lt 1 ]
  then
    echo $first_greeting
  else
    if [ $greeting_occasion -lt $greeting_limit ]
    then
      echo $later_greeting
    else
      echo $last_greeting
    fi
  fi
  greeting_occasion=$((greeting_occasion + 1))
done

Notice I use -le instead of -lt on the while loop.

1 Like

Can someone help me in executing the following three commands at the end of the Build a build script project -

  • Copy secretinfo.md but replace “42” with “XX”.
  • Zip the resulting build directory.
  • Give the script more character with emojis.
  • If you are familiar with git , commit the changes in the build directory.
1 Like

Hi micro,

Thanks for your code, it really help me with putting together a usable code for the additional instructions.

I thought I would share in hopes that it could help someone like you’ve helped me

#!/bin/bash

first_greeting=$" "
later_greeting=$" "
a_different_greeting=$" "

echo "Provide three different greetings:"
read first_greeting
read later_greeting
read a_different_greeting

greeting_occasion=0
greeting_limit=$1

while [ $greeting_occasion -le $greeting_limit ]
do
  if [ $greeting_occasion -lt 1 ]
  then
    echo $first_greeting
  else
    if [ $greeting_occasion -lt $greeting_limit ]
    then
      echo $later_greeting
    else
      echo $a_different_greeting
    fi
  fi
  greeting_occasion=$((greeting_occasion + 1))
done```

### Terminal Window
$ ./script.sh 5
Provide three different greetings:
Nice to meet you!
How are you doing?
Howdy
Nice to meet you!
How are you doing?
How are you doing?
How are you doing?
How are you doing?
Howdy

My code was not accepted 3 times in this module. When I asked for the solution it showed the code as I typed it. On the last exercise I was never able to create the greet 3 alias. When I clicked in the solution the code wasn’t even there.