4

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.

1 Answer 1

11

Bash uses spaces to tokenise scripts. The line:

if [[ $1 =-v ]]

should be:

if [[ $1 = -v ]]
Sign up to request clarification or add additional context in comments.

1 Comment

I could have sworn I'd tried that, but obviously not. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.