Codecademy Forums

FAQ: Learn Bash Scripting - Aliases

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

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!

Hello. I am trying to find out what I did wrong here. This is a copy of my code. The first line starts at number 1.

#!/bin/bash
first_greeting=“Nice to meet you!”
later_greeting=“How are you?”
greeting_occasion=0
greeting_limit=$1
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 I try to run my code, I keep getting a unary operator expected error on line 6. Please advise on what I’ve done wrong, because I don’t understand it.

If you write

alias greet3="./script.sh 3"

according to describing (!!on command line) and then write greet3 your script will work.
But I don´t understand why script it can´t be start by normal way???
And why
greeting_limit in the script is written in this way

greeting_limit=$1 ???

I hope I will figure out.

2 Likes

I think the $ sign in greeting_limit=$1 tells it to use the first number that is written by the user in the alias (the first input). So if you try to run it just by typing ./script.sh, you get an error because there is no number for it to use for the greeting_limit.

To complete this exercise, type alias greet3=’./script.sh 3’ in the bash terminal (not in script.sh), then type greet3 to run the script using this alias

You can run the script without the alias by typing ./script.sh and then a single number or a list of numbers, and the script will use the first number that you type. For example, if you type ./script.sh 1 2 3 then the script will run and will show you one greeting.

However - I thought that if you change the script.sh to include greeting_limit=$2 instead of $1 then it would use the second number in a list - but it still appears to use the first number. Any ideas anyone?

2 Likes

#!/bin/bash
first_greeting=“Nice to meet you!”
later_greeting=“How are you?”
greeting_occasion=$2
greeting_limit=$1

echo $greeting_occasion
echo $greeting_limit

this should allow you to understand it more, you can change the variable inputs and keep printing to the terminal. you have to hit run to save the code before running it in the terminal or the changes wont have taken affect. hope this helps, took me a few minutes to figure out how to test it myself.

Here my code. It works. But it is not verified as solution.

alias greet3=’./script.sh “3”’

what is the issue of doing it this way?
“” is necessary for string but is optional for integers?

1 Like

That is how anyone would have tried to set their greet3 alias if they followed the syntax provided in the example. I did this also with the 3 inside quotation marks and couldn’t get past that section. Very frustrating…

1 Like

this excercise is bugged. when you request the solution it shows litterally the same as the start of this excercise…

you must first call the profile with this command:
source ~/.bash_profile
then you type greet3

The first exercise in this lesson show us a snippet of code:

./script.sh 5 #greets 5 times

What significance is this to the lesson? To the exercise? It does not seem related to anything in this lesson. This is confusing, since that syntax has not been introduced anywhere previous.