Why equal to operator does not work if it is not surrounded by space?

前端 未结 4 2129
时光取名叫无心
时光取名叫无心 2020-11-22 14:29

I tried the following script

#!/bin/bash
var1=\"Test 1\" 
var2=\"Test 2\"
if [ \"$var1\"=\"$var2\" ] 
  then 
    echo \"Equal\" 
  else 
    echo \"Not equa         


        
4条回答
  •  广开言路
    2020-11-22 14:58

    In bash the best is to use [[ ]]:

    x="test"
    y="test"
    if [[ "${x}" = "${y}" ]]; then
        echo "Equals"
    else
        echo "No equals"
    fi
    

提交回复
热议问题