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 ...
随机推荐
- 对PostgreSQL的prepared statement的深入理解
看官方文档: http://www.postgresql.org/docs/current/static/sql-prepare.html PREPARE creates a prepared sta ...
- 今天写一些 有关iOS 多图片组合 成一张图片的问题。保持原像素不变
1.要求:服务器给一张图片模板,要在模版上镂空,然后添加一些别的图片,然后组合成一张图,这个模版的像素 不是固定的,有可能比 当前手机屏幕大.所以,在组合截图的时候,有一定的要求. 贴代码: /** ...
- 60款开源云应用【Part 2】(60 Open Source Apps You Can Use in the Cloud)
60款开源云应用[Part 2](60 Open Source Apps You Can Use in the Cloud) 本篇翻译自http://www.datamation.com/open-s ...
- spring关于“transactionAttributes”的相关配置
spring关于"transactionAttributes"的相关配置 <bean id="baseTransactionProxy" class=&q ...
- W5500问题集锦(二)
attachment_id=5620" rel="attachment wp-att-5620" style="margin:0px; padding:0px; ...
- 关于开源的RTP——jrtplib的使用
session.BeginDataAccess(); if (session.GotoFirstSource()){ do{ RTPPacket *packet; while ((packet = s ...
- java_jdbc_可滚动结果集与分页
public static void create2(int i) { Connection conn = null; Statement st = null; ResultSet rs = null ...
- 【转】如何在Mac上撰寫C++程式
原文: http://www.macuknow.com/node/4901 本文使用的开发环境:Xcode 5.其实步骤很简单,只需要简单的几步就ok了. 點選Create a new Xcode p ...
- PHP获取远程图片并调整图像大小
<?php /** * *函数:调整图片尺寸或生成缩略图 *修改:2013-2-15 *返回:True/False *参数: * $Image 需要调整的图片(含路径) * $Dw= ...
- MySQL入门笔记
MySQL入门笔记 版本选择: 5.x.20 以上版本比较稳定 一.MySQL的三种安装方式: 安装MySQL的方式常见的有三种: · rpm包形式 · 通用二进制 ...