syntax error near unexpected token else
1:
定义变量时, =号的两边不可以留空格. 这里不能添加的原因是 添加了空格一般是用来表示判断的
eg:
gender=femal------------right
gender =femal-----------wrong
gender= femal-----------wrong
2
条件测试语句 [ 符号的两边都要留空格 . //这条真的比较膈应人
eg:
if [ $gender = femal ]; then-------right.
echo "you are femal";
fi
if[ $gender…-----------------------wrong
if [$gender…----------------------wrong.
3
条件测试的内容,如果是字符串比较的话, 比较符号两边要留空格!
eg:
if [ $gender = femal ]; then-------right.
if [ $gender= femal ]; then--------wrong.
if [ $gender=femal ]; then---------wrong.
4
如果if 和 then写在同一行, 那么,注意, then的前面要跟上 ; 号.
如果 then 换行写, 那么也没问题.
eg:
if [ $gender = femal ]; then-------right.
if [ $gender = femal ]
then-------------------------------right.
if [ $gender = femal ] then-------wrong. then前面少了 ; 号.
提示出错信息:
syntax error near unexpected token then 这就话出错还可能是由于第二条 “[” 左右都要有空格造成的
同理,还有很多出错信息 比如
syntax error near unexpected token fi 等都是这样引起的.
5
if 后面一定要跟上 then. 同理
elif 后面一定要跟上 then.
不然提示出错信息:
syntax error near unexpected token else
1)if 语句后面需要跟着then,同时前面要有分号;
空格非常重要,shell 会认为空格前的为一个命令,如果a=3 认为是赋值操作,如果写成a = 3,那么就会认为a为一个命令 this=
ls -l |grep '^-' | wc -l
操作符之间要用空格分开 ,如 test ! -d $1,其中的!和-d就要用空格分开
空格是命令解析中的重要分隔符
syntax error near unexpected token else相关推荐
- -bash:syntax error near unexpected token '('
在Xshell5中编写int main(int argc,char** argv)时, 出现-bash:syntax error near unexpected token '(' : 可是我是按照 ...
- syntax error near unexpected token
2019独角兽企业重金招聘Python工程师标准>>> shell脚本,在自己机器上运行正常,给同事,运行报错syntax error near unexpected token ` ...
- linux shell脚本无法执行,报错syntax error near unexpected token `$'\r''解决方法
运行shell脚本时出现:syntax error near unexpected token `$'\r"的错误,一般是格式的问题,比如直接从txt文档拷贝过来的内容: 解决方法:sed ...
- 成功解决.sh: line 6: syntax error near unexpected token `do
成功解决.sh: line 6: syntax error near unexpected token `do 目录 解决问题 解决思路 解决方法 T1.修改格式系统间不兼容的格式
- 成功解决bash syntax error near unexpected token from
成功解决bash syntax error near unexpected token from 目录 解决问题 解决思路 解决方法 解决问题 -bash: syntax error near une ...
- shell if else 用法 syntax error near unexpected token `then'
1. 错误 #!/bin/bash platform=$1 if[ "$platform" = "ibmaix64" ] then echo &q ...
- shell编程报错:“syntax error near unexpected token `”
今天写了个shell脚本,在自己机器上运行正常,给同事,运行报错syntax error near unexpected token `,左看右看shell脚本没有问题,没有办法google搜索,发现 ...
- svn之bash: syntax error near unexpected token `(‘ 解决办法
1.问题 svn update *****/网易(杭州)网络有限公司SSL-20170623001 出现这个错误 bash: syntax error near unexpected token `( ...
- 记一次坑爹报错之旅 -bash: /etc/profile: line 11: syntax error near unexpected token
昨晚修改了环境变量后,进行重置服务时 source /etc/profile 报错 [root@localhost etc]# source /etc/profile -bash: /etc/prof ...
- rm删除报错 :-bash: syntax error near unexpected token `('
删除报错 :-bash: syntax error near unexpected token `(' root@ubuntu:~# rm -rf zabbix-release_4.2-1+xenia ...
最新文章
- 爱立信前CEO Hans Vestberg成为Verizon三巨头之一
- 模块全解======ruby的类是单继承生物、所以出现了module、实现了多继承
- 从一个疯狂下载者变成一个学习者
- 编制网站首页的基本原则
- ActiveX控件打包成Cab置于网页中自动下载安装
- Java 中的日期与时间
- 禅道测试套件怎么用_【分享】—如何学习软件测试
- freeradius mysql web_使用daloRADIUS Web程序管理FreeRADIUS服务
- css不同大小字体底部对齐
- 数据结构:图的基本概念
- 计算机辅助工业设计应用软件,计算机辅助工业设计软件(CAID)ProE与Rhino对比研究...
- python3正则re的使用
- 让创意设计更加简单:在线设计平台Canva登陆中国
- Teams Meeting 实时事件通知
- 计算机网络——互联网上的音/视频服务
- 【JAVA类与对象----5(static、代码块)】
- android 开发论坛资源URL
- ParameterAttribute的区别
- 初使用maven遇到各种问题记录
- 计算机发展的几个重要事件,15件在计算机发展史中具有里程碑意义的事件