shell if else 用法 syntax error near unexpected token `then'
2016-03-24 14:30
621 查看
1. 错误
#!/bin/bashplatform=$1
if[ "$platform" = "ibmaix64" ]
then
echo "$platform"
else
echo "hello ooo"
fi
Error : syntax error near unexpected token `then'
原因: 条件语句 [ 符号的两边都要留空格
if [ $platform = "winx64" ]-----------------------right 绿色标记为空格
if[ $platform = "winx64" ]-----------------------wrong
if [$platform = "winx64" ]-----------------------wrong
2. 总结
2.1 空格a.定义变量时, =号的两边不可以留空格
b.if语句 [ 符号的两边都要留空格
c.字符串比较, =两边要留空格
d. if 和then 在同一行 要加;
2.2 if 语句
#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
fi
#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
else
echo "a is not equal to b"
fi
#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
elif [ $a -gt $b ]
then
echo "a is greater than b"
elif [ $a -lt $b ]
then
echo "a is less than b"
else
echo "None of the condition met"
fi
相关文章推荐
- shell输入输出重定向
- bash常用快捷键
- 【shell编程基础0】bash shell编程的基本配置
- Bash的基本功能
- (转)73条日常Linux shell命令
- Linux平台搭建Jenkins+Maven+Shell实现自动化构建部署
- linux下监视进程 崩溃挂掉后自动重启的shell脚本
- shell 脚本 修改系统时间
- centos 防火墙 iptables 用shell代码来添加
- shell--内建命令--exec
- Linux shell 变量 数学 运算
- Bash空格的那点事
- 常用的shell脚本
- [Android] 为Android安装BusyBox —— 完整的bash shell
- shell 命令学习
- shell 随机从文件中抽取若干行的实现方法
- 关于shell的几个不为人知却十分有用的命令分享
- hadoop常用shell脚本总结
- shell学习(一)hello world
- -bash: ssh: command not found的解决办法