Task2.sh issue with autograder

Hi!

Below you will find my code for task2.sh

#!/bin/bash

instruction=$1

if [ $instruction=="small_square" ]; then
    rosrun linux_exam small_square.py

elif [ $instruction=="medium_square" ]; then
    rosrun linux_exam medium_square.py

elif [ $instruction=="big_square" ]; then
    rosrun linux_exam big_square.py
fi

It passes the small_square test but fails the medium_square and big_square tests. I doubt there is any issue with my code since when I tested it myself it indeed was crossing distances correctly (0.5 for small, 1 for medium and 2 for big). Thanks for the great courses!

Hi @sisaha,

the problem lies in the “==”

I would put the $instruction inside double quotes, use a single “=” sign and put a space around it.

Like below:

if [ "$instruction" = "small_square" ]; then
    do_something; 
else
    do_something_else; 
fi 

That should work.

Hi @ralves and @sisaha,

It is interesting that @ralves’ solution solved the issue. I double-checked, and it really worked! :slight_smile:
However, @sisaha’s original solution was almost right: you should use spaces before and after the ==. So, this should also work:

#!/bin/bash

    instruction=$1

    if [ $instruction == "small_square" ]; then
        do_something; 
    else
        do_something_else; 
    fi