0

I have problem when check input from shell, can someone help me:

#!/bin/bash
export type=$1    
echo "$type"
if [$type=="kvm"]
then
    echo "true"
else
    echo "false"
fi

I expect shell will print true but the result is:

> bash ~/my_scripts/dssh.sh kvm
kvm
/home/xdoabui/my_scripts/dssh.sh: line 15: [kvm==kvm]: command not found
false
bxdoan
  • 1,216
  • 6
  • 21
  • 5
    give space between `[` and `$type` and `"` and `]` like `if [ "$type" == "kvm" ]` – P.... Nov 16 '17 at 06:27
  • Great, It works now, thank a lot :) – bxdoan Nov 16 '17 at 06:33
  • Addendum to the first comment: `[` is a program also named `test`, and `$type`, `==`, `"kvm"`, and `]` are its arguments. Thus the spaces are mandatory. – clemens Nov 16 '17 at 06:36
  • 1
    Also, `=` is more portable than `==` in a `[ ]` (aka `test`) expression. Bash tolerates `==` as an equivalent, but not all shells (and versions of `/bin/test`) do. And [shellcheck.net](http://www.shellcheck.net) will spot a lot of these common mistakes. – Gordon Davisson Nov 16 '17 at 06:54

0 Answers0