I'm taking the linux basics for robotics course, and am on exercise 3.2.1 and I tried to run the demo.sh file and got this error,

unary operator expected at lines 5, 15, 25

Hi @Yogesh_G,

Welcome to our community.

This error message happens because the script is expecting to have an argument.

In other words, you called ./demo.sh, but instead, you should call:

./demo.sh rotate

and then, after stopping the command above using CTRL+C, you could:

./demo.sh stop

This is basically the reason why you see this error message.

But I agree that the script has to be improved.

If you replace all $ARG1 in the code with "$ARG1", then this error also would be gone.

I agree that we should have put the commas in the script, or put an error message in case the user does not provide an argument.

I think this could also be a good exercise for you, what do you think?

You could replace the first lines with:

#!/bin/bash

ARG1=$1

if [ "$ARG1" == "" ]; then 
    echo "Please, provide an argument. E.g.: ./demo.sh rotate"
    exit 1
fi

Then the code will detect when someone calls the script without an argument.

Keep pushing your Linux learning.

Hey! thank you for the help.

1 Like