Why does this simple bash code give a syntax error?

Posted by Tim on Stack Overflow See other posts from Stack Overflow or by Tim
Published on 2010-06-15T12:07:18Z Indexed on 2010/06/15 12:12 UTC
Read the original article Hit count: 171

Filed under:
|

I have the following bash code, which is copied and pasted from "bash cookbook" (1st edition):

#!/bin/bash

VERBOSE=0;
if [[ $1 =-v ]]
then
    VERBOSE=1;
    shift;
fi

When I run this (bash 4.0.33), I get the following syntax error:

./test.sh: line 4: conditional binary operator expected
./test.sh: line 4: syntax error near `=-v'
./test.sh: line 4: `if [[ $1 =-v ]]'

Is this as simple as a misprint in the bash cookbook, or is there a version incompatibility or something else here? What would the most obvious fix be? I've tried various combinations of changing the operator, but I'm not really familiar with bash scripting.

© Stack Overflow or respective owner

Related posts about bash

Related posts about syntax-error