Stephan
Stephan

Reputation: 155

simple unix shell programming errors about unary operator

I have been having some difficulties recently about unary operator. Here is the code below.

#!/bin/bash


if [ ${op:0:1} = "-" ];
then
        echo "debug: option!";
fi

I am aware about the space requirement I still don't know the reason it won't compile. This is just a simple vi code after all.

Upvotes: 0

Views: 81

Answers (1)

oliv
oliv

Reputation: 13259

As mentionned in the comment, your op variable is likely empty.

In order to avoid the bash error, use double quote in your if statement:

if [ "${op:0:1}" = "-" ];
then
        echo "debug: option!";
fi

Upvotes: 3

Related Questions