我正在尝试使用Bash(使用Ubuntu)获得一个if声明:
#!/bin/bash
s1="hi"
s2="hi"
if ["$s1" == "$s2"]
then
echo match
fi
Run Code Online (Sandbox Code Playgroud)
我尝试了各种形式的if语句,使用[["$s1" == "$s2"]],有和没有引号,使用=,==和-eq,但我仍然得到以下错误:
[hi:命令未找到
我查看了各种网站和教程并复制了这些内容,但是它不起作用 - 我做错了什么?
最后,我想说是否$s1包含$s2,所以我该怎么做?
我刚刚解决了空位...:/我怎么说包含?
我试过了
if [[ "$s1" == "*$s2*" ]]
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
为什么这么简单的脚本不起作用?
1 for i in {1..6}
2 do
3 if[ "$i" -lt "3" ]
4 then
5 echo "a"
6 else
7 echo "b"
8 fi
9 done
Run Code Online (Sandbox Code Playgroud)
要么
1 for i in {1..6}
2 do
3 if[ "$i" < 3 ]
4 then
5 echo "a"
6 else
7 echo "b"
8 fi
9 done
Run Code Online (Sandbox Code Playgroud)
呃:
./test.sh: line 4: syntax error near unexpected token `then'
./test.sh: line 4: ` then'
Run Code Online (Sandbox Code Playgroud)