[问题]新手提问简单的问题

sh/bash/dash/ksh/zsh等Shell脚本
回复
kaixinlaohe
帖子: 12
注册时间: 2007-01-08 19:55

[问题]新手提问简单的问题

#1

帖子 kaixinlaohe » 2007-02-01 16:59

#!/bin/bash
strvar="hello"
#定义一个字符串变量
if [${strvar} = "he"] 是否与he相等
then
echo correct
else
echo wrong
fi

运行的时候出现了这个错误是怎么回事啊?
[he: command not found
firefish
帖子: 284
注册时间: 2007-01-18 16:14
来自: CHINA

#2

帖子 firefish » 2007-02-01 23:18

bash的相等好像不是这样比较的吧,自己搜搜看,这好像连C语言里面都不是这么比较 的
头像
5451vs5451
帖子: 345
注册时间: 2006-07-14 18:56
来自: Apple Valley, Planet Tux, Linux System

Re: [问题]新手提问简单的问题

#3

帖子 5451vs5451 » 2007-02-01 23:51

kaixinlaohe 写了:#!/bin/bash
strvar="hello"
#定义一个字符串变量
if [${strvar} = "he"] 是否与he相等
then
echo correct
else
echo wrong
fi

运行的时候出现了这个错误是怎么回事啊?
[he: command not found
方括号前后都要空格。
kaixinlaohe
帖子: 12
注册时间: 2007-01-08 19:55

#4

帖子 kaixinlaohe » 2007-02-02 23:13

是的,楼上对了,谢谢!
回复