This question already has an answer here:
(这个问题已经在这里有了答案:)
I'm trying to get an if
statement to work in Bash (using Ubuntu ):
(我正在尝试让if
语句在Bash中工作(使用Ubuntu ):)
#!/bin/bash
s1="hi"
s2="hi"
if ["$s1" == "$s2"]
then
echo match
fi
I've tried various forms of the if
statement, using [["$s1" == "$s2"]]
, with and without quotes, using =
, ==
and -eq
, but I still get the following error:
(我已经尝试过各种形式的if
语句,使用[["$s1" == "$s2"]]
,使用和不使用引号,使用=
, ==
和-eq
,但是仍然出现以下错误:)
[hi: command not found
([hi:找不到命令)
I've looked at various sites and tutorials and copied those, but it doesn't work - what am I doing wrong?
(我查看了各种站点和教程并复制了这些站点和教程,但是它不起作用-我在做什么错?)
Eventually, I want to say if $s1
contains $s2
, so how can I do that?
(最终,我想说一下$s1
包含$s2
,那我该怎么做呢?)
I did just work out the spaces bit.. :/ How do I say contains?
(我只是算出空格位..:/我怎么说包含?)
I tried
(我试过了)
if [[ "$s1" == "*$s2*" ]]
but it didn't work.
(但这没用。)
ask by Mr Shoubs translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…