fromhttp://blog.csdn.net/panda19881/article/details/6626727
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,同时前面要有分号;
2) 空格非常重要,shell 会认为空格前的为一个命令,如果a=3 认为是赋值操作,如果写成a = 3,那么就会认为a为一个命令 this=`ls -l |grep ‘^-’ | wc -l `
3) 操作符之间要用空格分开 ,如 test ! -d $1,其中的!和-d就要用空格分开
空格是命令解析中的重要分隔符
6. 命令和其后的参数或对象之间一定要有空格
if [ -x"~/Workspace/shell/a.sh" ];then
只有 -x 后有空格才表示紧跟其后的字符串是否指向一个可执行的文件名,否则就成了测试 -x"~/Workspace/shell/a.sh" 这个字符串是不是空。
7.取变量值的符号'$'和后边的变量或括号不能有空格
分享到:
相关推荐
Linux Shell编程经典著作:<br>第一部分SHELL<br>|_文件安全与权限<br>|_使用find和xargs<br>|_后台执行命令<br>|_文件名置换<br>|_shell输入与输出<br>|_命令执行顺序<br>第二部分文本过滤<br>|_正则表达式介绍<br>...
Linux Shell编程经典著作:<br>第一部分SHELL<br>|_文件安全与权限<br>|_使用find和xargs<br>|_后台执行命令<br>|_文件名置换<br>|_shell输入与输出<br>|_命令执行顺序<br>第二部分文本过滤<br>|_正则表达式介绍<br>...
Linux Shell编程经典著作:<br>第一部分SHELL<br>|_文件安全与权限<br>|_使用find和xargs<br>|_后台执行命令<br>|_文件名置换<br>|_shell输入与输出<br>|_命令执行顺序<br>第二部分文本过滤<br>|_正则表达式介绍<br>...
<br>目 录<br>译者序<br>前言<br>第一部分 shell<br>第1章 文件安全与权限 1<br>1.1 文件 1<br>1.2 文件类型 2<br>1.3 权限 2<br>1.4 改变权限位 4<br>1.4.1 符号模式 4<br>1.4.2 chmod命令举例 5<br>1.4.3 绝对...
The shell environment should contain shell=<pathname>/myshell where <pathname>/myshell is the full path for the shell executable (not a hardwired path back to your directory, but the one from which it...
<br />基础s h e l l编程<br />16、shell脚本介绍<br />17、条件测试<br />18、控制流结构<br />19、shell 函数<br />20、向脚本传递参数<br />21、创建屏幕输出<br />22、创建屏幕输入<br />23、调试脚本<br />24、...
adb shell cp [options] <source> <dest> 16 adb shell mv [options] <source> <dest> 16 网络命令(NetWork) 17 adb shell netstat 17 adb shell ping 17 adb shell netcfg 18 adb shell ip [OPTIONS] OBJECT 18 ...
shell基础1:文件安全与权限 2<br>shell基础2:查找技巧,find及xargs的使用 25<br>shell基础3和4:后台(crontab,at,&,nohup)及(*,?,[]等)shell基础5:输入/输出(echo,read,cat,管道,tee,重定向等)shell基础8:文本...
系统软件开发<br>4.1 软件开发流程<br>4.2 软件开发环境<br>4.3 文件系统<br>4.4 软件开发工具<br>4.4.1 GNUPro工具<br>4.4.2 Nios OCI调试模块<br>4.4.3 Nios OCI调试控制台<br>4.4.4 Nios SDK Shell...
<br><br>// 得到Shell32的版本号,并依此设置结构成员cbSize的大小 - 注意:MSDN文档中关于这部分的说明有点模糊不清(见本文后面),所以我并不确定下面的代码是否完全正确<br><br> ULONGLONG ullVersion =<br> ...
The Missing Code Library <br> Chapter 2 - Improving on User Commands <br> Chapter 3 - Creating Utilities <br> Chapter 4 -...Chapter 11 - Mac OS X Scripts <br> Chapter 12 - Shell Script Fun and Games <br>
Shell Basics<br>Module 7 — Shell Advanced Features<br>Module 8 — File Name Generation<br>Module 9— Quoting<br>Module 10 — Input and Output Redirection<br>Module 11 — Pipes<br>Module 12 — Using ...
在掌握一些最基本的linux命令后,如果想进一步linux命令或为以后能读懂内核makefile,请关注它,希望对你有用
1,01.zip<br>Output<br>显示所有的调试信息(5KB)<END><br>2,02.zip<br>Some general debugging tips<br>一般的调试技巧(11KB)<END><br>3,03.zip<br>Debugging ISAPI extension<br>调试ISAPI扩展(4KB)<END><br>4,04....
UNIX 快速查询手册<br>1.... SHELL编程 10<br>10. 其它 16<br>11. 正则表达式 18<br>12. 常用命令 18<br>13. awk介绍 21<br>14. sed介绍 25<br>15. tr介绍 27<br>16. Vi的三种工作状态 28<br>17. MAKE介绍 31<br><br>
Interacting with the Database <br>Chapter 6: Advanced DBI <br>Chapter 7: ODBC and the DBI <br>Chapter 8: DBI Shell and Database Proxying <br>Appendix A: DBI Specification <br>Appendix B: Driver and ...
Wicked Cool Shell Scripts: 101 Scripts for Linux, Mac OS X, and Unix Systems<br><br>This cookbook of useful, customizable, and fun scripts gives you the tools to solve common Linux, Mac OS X and UNIX ...
实验任务一:<br>编写一个Shell过程完成如下功能(必须在脚本中使用函数):<br>1、合并两个$1、$2文件为$3,并显示。<br>2、如果缺少$3,那么先报告缺少$3,然后将合并后的内容输出到mydoc.txt。如果有$3,就合并到...
工程.pdf<br>3.Shell和Browser.pdf<br>4.CrossWind Debugger的使用.pdf<br>5.实时多任务.pdf<br>6.WindView工具.pdf<br>7.信号量编写.pdf<br>8.任务间通信.pdf<br>9.内存管理.pdf<br>10.异常、中断和时钟.pdf<br>11....
可供参考的linux解释器源码,包含了简单命令,复合命令,以及后台执行命令的相关实现