开发者

Why does this simple bash code give a syntax error?

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开发者_如何学JAVA 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.


Bash uses spaces to tokenise scripts. The line:

if [[ $1 =-v ]]

should be:

if [[ $1 = -v ]]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜