# Advanced Utilities Exercise 3.2.1 Passing parameters to a bash script

**URL:** <https://get-help.theconstruct.ai/t/advanced-utilities-exercise-3-2-1-passing-parameters-to-a-bash-script/23642>\
**Category:** Linux Basics For Robotics\
**Created:** [April 9, 2023, 11:00pm UTC](https://get-help.theconstruct.ai/t/advanced-utilities-exercise-3-2-1-passing-parameters-to-a-bash-script/23642 "2023-04-09T23:00:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kozzix](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/kozzix/32/6688_2.png) [@Kozzix](https://get-help.theconstruct.ai/u/Kozzix)\
**Post date:** [April 9, 2023, 11:00pm UTC](https://get-help.theconstruct.ai/t/advanced-utilities-exercise-3-2-1-passing-parameters-to-a-bash-script/23642/1 "2023-04-09T23:00:27Z")

</div>

I have no idea what we are doing here. Did I miss a lesson? I have already searched and found one other question about this but that confused me even more.

**" For instance, let’s have a look at the script you used in this first demo, called demo.sh . I will just tell you the location of the script. It’s in the following path: /home/simulations/public\_sim\_ws/src/all/ros\_basics\_examples/linux\_demo/ .**

**The rest you should be able to do by yourself at this point**." Why would I be able to do this when we haven’t learned it?

There is no demo script in this lesson, that pathway is not in this lesson. I am completely lost.

“” Create a bash script that does the following:

- It will receive one parameter, which will contain either:

- If the parameter is **circle** , the script will execute the **move\_bb8\_circle.py** file.

- If the parameter is **forward\_backward** , the script will execute the **move\_bb8\_forward\_backward.py** file.

- If the parameter is **square** , the script will execute the **move\_bb8\_square.py** file.“”

I tried this and was able to get this to print enter circle, forward etc… But when I entered circle it just gave me an error.

Can someone please help me. Thank you. Jason

**user:~/catkin\_ws/src/linux\_course\_files/move\_bb8\_pkg/my\_scripts$ ./thebash.sh**  
**Please enter one of the following;**  
**circle**  
**forward\_backward**  
**square**  
**user:~/catkin\_ws/src/linux\_course\_files/move\_bb8\_pkg/my\_scripts$ circle**  
**bash: circle: command not found**  
**user:~/catkin\_ws/src/linux\_course\_files/move\_bb8\_pkg/my\_scripts$**

---

<div class="post-metadata">

**Author:** ![girishkumar.kannan](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/girishkumar.kannan/32/6994_2.png) [@girishkumar.kannan](https://get-help.theconstruct.ai/u/girishkumar.kannan)\
**Post date:** [April 10, 2023, 5:13am UTC](https://get-help.theconstruct.ai/t/advanced-utilities-exercise-3-2-1-passing-parameters-to-a-bash-script/23642/2 "2023-04-10T05:13:10Z")

</div>

Hi @Kozzix ,

I believe that you have not understood `bash` programming. Also I think you do not know how to use the terminal.

> [@Kozzix](#):
>
> **user:~/catkin\_ws/src/linux\_course\_files/move\_bb8\_pkg/my\_scripts$ ./thebash.sh**  
> **Please enter one of the following;**  
> **circle**  
> **forward\_backward**  
> **square** \< - - - your program ended here
> 
> So the line below will have no effect as it will try to call a program called “circle”  
> **user:~/catkin\_ws/src/linux\_course\_files/move\_bb8\_pkg/my\_scripts$ circle**  
> **bash: circle: command not found**
> 
> **user:~/catkin\_ws/src/linux\_course\_files/move\_bb8\_pkg/my\_scripts$**

The instructions for you is to pass the shape as a command line operator.  
So your command will look like below:

```bash
./my_bash_script.sh circle # to perform circle move
./my_bash_script.sh forward_backward # to perform font-back move
./my_bash_script.sh square # to perform square move

```

You must first understand how terminal works before you can continue to make `bash` scripts.

Regards,  
Girish

---

<div class="post-metadata">

**Author:** ![Kozzix](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/kozzix/32/6688_2.png) [@Kozzix](https://get-help.theconstruct.ai/u/Kozzix)\
**Post date:** [April 10, 2023, 9:47pm UTC](https://get-help.theconstruct.ai/t/advanced-utilities-exercise-3-2-1-passing-parameters-to-a-bash-script/23642/3 "2023-04-10T21:47:33Z")

</div>

I’m not sure what help this was. But thank you for the attempt.

---

<div class="post-metadata">

**Author:** ![ralves](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/ralves/32/7039_2.png) [@ralves](https://get-help.theconstruct.ai/u/ralves)\
**Post date:** [April 11, 2023, 12:25pm UTC](https://get-help.theconstruct.ai/t/advanced-utilities-exercise-3-2-1-passing-parameters-to-a-bash-script/23642/4 "2023-04-11T12:25:38Z")

</div>

Hi @Kozzix,

here is the possible content of _ **`thebash.sh`** _ script.

```auto
#!/bin/bash

argument=$1

function help(){
    echo "Please enter one of the following: circle, forward, backward, square"
    echo
    echo "Example: ./thebash.sh circle"
    exit 1
}

if [["$argument" == "circle"]]; then
    echo "Well done, you typed CIRCLE"
elif [["$argument" == "square"]]; then
    echo "Well done, you typed SQUARE"
else
    echo "Oh, you typed something else: $argument"
    help
fi

```

If you paste this content in a file ending with the .sh extension (example: _ **test.sh** _), and then give it execute permissions with _ **chmod +x test.sh** _, and run it with _ **./test.sh** _, it will tell you that the correct way of running would be:

```auto
./test.sh circle

```

Please let us know it things are now clearer

---

<div class="post-metadata">

**Author:** ![ralves](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/ralves/32/7039_2.png) [@ralves](https://get-help.theconstruct.ai/u/ralves)\
**Post date:** [July 3, 2023, 9:36pm UTC](https://get-help.theconstruct.ai/t/advanced-utilities-exercise-3-2-1-passing-parameters-to-a-bash-script/23642/5 "2023-07-03T21:36:55Z")

</div>


