syntax error near unexpected token `then'
#!/bin/bash
clear
function test
{
if[$1 -eq "root"]&&[$2 -eq "123456"]
then
echo "Right"
else
echo "Wrong"
fi
}
test root 123456
----------------------------
上面这个程序我执行时,报这个错误,刚接触shell,没想到它的语法这么……不说了,在网上找个原因,贴出正确的格式,并总结要注意的几点
=======================
#!/bin/bash
clear
function test
{
if [ $1-eq"root" ] && [ $2-eq"123456" ]
then
echo "Right"
else
echo "Wrong"
fi
}
test root 123456
==========================
总结:
1.if后要有空格
2.[] 中括号的开头和结尾要有空格!
3. [ $1-eq"root" ]中括号中的$1和-eq和"root"之间没有空格!
syntax error near unexpected token `then'的更多相关文章
- Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"
同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...
- Linux中syntax error near unexpected token 错误提示解决方法
Linux中syntax error near unexpected token ... 错误提示有一般有两种原因: 1)window和Linux下换行符不一致导致 window下的换行和Linux下 ...
- syntax error near unexpected token `then'问题的解决
#!/bin/bash #if program test echo 'a:' read a if [ "$a" = "English" ];then ...
- 使用cygwin出现syntax error near unexpected token'$'do\r
直接从csdn复制粘贴的.sh代码,放到cygwin下运行sh的时候出错syntax error near unexpected token'$'do\r 解决方法: 1.下载notepad++ 2. ...
- 写shell,运行出错:syntax error near unexpected token `$’do\r”
cygwin下面写shell,运行出错:syntax error near unexpected token `$’do\r” 写shell,运行出错:syntax error near unexpe ...
- 执行shell脚本提示“syntax error near unexpected token for((i=0;i<$length;i++))”
sh脚本例如以下: #!/usr/bin/env bash county="3 4 5 6 7 8 9 10 11 12 16 29 39 44 53 62 72 84 97 115 128 ...
- Linux 中出现的-bash: syntax error near unexpected token `
版权声明:本文为博主原创文章,未经博主允许不得转载. 在Linux 5中导入数据时,出现下面的错误. -bash: syntax error near unexpected token `(' 检查了 ...
- syntax error near unexpected token `do(写的shell脚本出现格式问题)--->1.问题2.展示信息3.解决方案
1问题:Linux和windows下的回车换行符不兼容的问题 [root@node-01 script]# sh start_zk.sh art_zk.sh: line 3: syntax error ...
- -bash:syntax error near unexpected token '('
在Xshell5中编写int main(int argc,char** argv)时, 出现-bash:syntax error near unexpected token '(' : 可是我是按照 ...
- -bash: /etc/profile: line 11: syntax error near unexpected token `$'{\r''报错问题解决
在Linux系统配置Java环境变量之后执行 source /etc/profile指令报:-bash: /etc/profile: line 11: syntax error near unexpe ...
随机推荐
- .NET加密配置文件connectionStrings节点
具体的可以参考petshop源码程序. 加密前: <connectionStrings> <add name="SQLProfileConnString" con ...
- tomcat 虚拟目录与显示目录中文件列表
虚拟目录: 该方法推荐使用,比较简单. 在%tomcat%\conf\Catalina\localhost(该目录可能需要手工创建)下新建一个文件abc.xml,注意文件名中的abc就表示虚拟目录的名 ...
- Postfix配置Q&A
原文地址:http://space.doit.com.cn/51460/viewspace-4943.html 在配置Postfix中遇到的一些问题及相关的解决方法,希望在遇到相同的问题时能起参考的作 ...
- 将图片序列保存为GIF文件
http://stackoverflow.com/questions/11459568/issue-with-rebuilding-and-saving-gifs-using-tgifimage 将图 ...
- Eclipse 开发WEB项目所遇问题 WebContent WebRoot
原文:http://blog.sina.com.cn/s/blog_525960510100jo0j.html 最近在做Web 项目时,新建了一个WEB 项目,如webdemo,eclipse默认的b ...
- 爱维帮---LVS
http://www.aiweibang.com/yuedu/125232503.html
- 文件I/O之fcntl函数
fcntl函数可以改变已打开的文件的性质. #include <fcntl.h> int fcntl( int filedes, int cmd, ... /* int arg */ ); ...
- Model
using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace iFlytekDemo ...
- 【转】Singleton单例模式
对于系统中的某些类来说,只有一个实例很重要,例如,一个系统中可以存在多个打印任务,但是只能有一个正在工作的任务:一个系统只能有一个窗口管理器或文件系统:一个系统只能有一个计时工具或ID(序号)生成器. ...
- jsp:session对象存储数据
public void setAttribute(String key,Object obj).session对象可以调用该方法将参数object指定的对象obj添加到session对象中,并为添加的 ...