代码: 全选
if ["$1"=="hello"]; then
echo "Hello,how are you?"
elif ["$1"==" "]; then
echo "You must input parameters, ex> $0 someword"
else
echo "The only parameter is 'hello'"
fi
代码: 全选
if ["$1"=="hello"]; then
echo "Hello,how are you?"
elif ["$1"==" "]; then
echo "You must input parameters, ex> $0 someword"
else
echo "The only parameter is 'hello'"
fi
复制?不行的啊~~O_O_BOT 写了:irc <ivan___> say: 别打,用复制:)
代码: 全选
cloudy@cloudy-laptop:~/scripts$ cat sh08.sh
#!/bin/bash -
#===============================================================================
#
# FILE: sh08.sh
#
# USAGE: ./sh08.sh
#
# DESCRIPTION: Show "Hello" from $1....
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: (), cloudy
# COMPANY:
# VERSION: 1.0
# CREATED: 10/22/2009 08:47:25 PM CST
# REVISION: ---
#===============================================================================
if ["$1"=="hello"]; then
echo "Hello,how are you?"
elif ["$1"==" "]; then
echo "You must input parameters, ex> $0 someword"
else
echo "The only parameter is 'hello'"
fi
set -o nounset # Treat unset variables as an error
cloudy@cloudy-laptop:~/scripts$ ./sh08.sh hello
./sh08.sh: line 20: [hello==hello]: command not found
./sh08.sh: line 22: [hello== ]: command not found
The only parameter is 'hello'
cloudy@cloudy-laptop:~/scripts$
人品爆发了,最初我也打了空格的,但是不能执行 刚才又仔细对照了下,竟然行了xiooli 写了:[和]与其他字母之间一定要有空格。
就是就是。xzap 写了:因为[就是test,test后面当然要空格啊。
不管怎么说,从表面上看,确实够苛刻的啦xzap 写了:因为[就是test,test后面当然要空格啊。不是bash语法严苛,函数或者命令后面不带空格直接带参数什么语言都不行的吧