shell 之空格
来源:互联网 发布:淘宝亲密付退款退到哪 编辑:程序博客网 时间:2024/04/30 02:57
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
定义变量时, =号的两边不可以留空格.
eg:
gender=femal------------right
gender =femal-----------wrong
gender= femal-----------wrong
2
条件测试语句 [ 符号的两边都要留空格.
eg:
if [ $gender = femal ]; then-------right.
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 ]
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 '^-' |
3) 操作符之间要用空格分开 ,如 test ! -d $1,其中的!和-d就要用空格分开
空格是命令解析中的重要分隔符
0 0
- shell 之空格
- shell 之空格
- shell 之空格
- Linux shell编程之空格
- shell空格
- shell 空格
- 嵌入式linux入门之shell 编程中空格的使用
- 初学shell,关于空格
- shell空格作用
- shell 处理空格
- shell 编程空格注意事项
- shell 去掉多余空格
- shell脚本中的空格
- SHELL与空格
- shell空格注意事项
- shell 的判断中的空格
- shell 去除行首空格
- shell删除文本文件中的空格
- HDU 5714 拍照(百度之星复赛)【宝宝的第一个爆0场】
- Java笔记(六) 对象群体的组织
- 数据结构-线性表_顺序表
- php接口写ios上传图片
- 字符串旋转 不同解法
- shell 之空格
- 【WebService】1.WebService概述和作用
- parse_url,pathinfo,basename三个函数都解析出了什么
- LeetCode Insertion Sort List(单链表插入排序)
- 农村土地确权之系列文档 —— 承包方代表变更申请书
- Calibration of Short Range 2D Laser Range Finder for 3D SLAM Usage
- 浅谈网络世界中的Power Law现象(一) 什么是Power Law
- vector
- 使用 UNIX 的 10 个良好习惯