shell 空格问题
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 换行写, 那么也没问题.(bash:==,dash =)
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就要用空格分开
空格是命令解析中的重要分隔符
shell 空格问题的更多相关文章
- 坑爹的shell 空格
shell 空格很敏感,被线上代码坑了,占个位,回头好好整理一下
- ISCC的 Web——WP
比赛已经结束了,自己做出来的题也不是很多,跟大家分享一下 第一题:比较数字大小 打开连接 在里面随意输入一个值,他会提示数字太小了 那么我们输入他允许的最大值试试 他还是提示太小了 我们知道做web‘ ...
- Jenkins-自动部署,备份
Jenkins-自动部署,备份 问题导入: 环境: CentOS 7, Tomcat 8.5, Jdk 1.8, Maven 3.25 ,Jenkins war包 2.x 原因: 每次部署 ...
- Shell中的空格和引号
空格对于linux的shell是一种很典型的分隔符,所以给变量赋值的时候中间不能够有空格.而单引号和双引号,都是为了解决中间有空格的问题.比如string1=this is a string,这样执行 ...
- shell替换一个或多个空格为逗号
(1)把文本中的一个或者多个空格替换为逗号 文本内容如下: # cat text 1 2 4 2 2 3 4 3 3 4 4 4 4 2 4 (2)shell程序代码为: # cat text | s ...
- shell脚本 空格
1.定义变量时, =号的两边不可以留空格. eg: gender=femal----right gender =femal---–wrong gender= femal---–wrong 2.条件测试 ...
- shell变量赋值 不能有空格的原因
典型例子: a=date echo $a 成立 a =date echo $a 不成立 其实原因很简单 shell在解释命令时的原则是第一个符号标记只能是程序或者命令,有空格的时候第 ...
- shell实现trim函数-去除字符串两侧的空格(包括tab,space键)
shell实现trim函数效果去除字符串两侧的空格,以下三个命令等价,都能实现 sed 's/^\s*//' totrim.txt |sed 's/\s*$//'>trimed.txtsed ' ...
- shell/bash 让vi/vim显示空格,及tab字符
shell/bash 让vi/vim显示空格,及tab字符 Vim 可以用高亮显示空格和TAB.文件中有 TAB 键的时候,你是看不见的.要把它显示出来::set listTAB 键显示为 ^I, ...
随机推荐
- 字符串匹配—KMP 扩展KMP Manacher
kuangbin字符串专题传送门--http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70325#overview 算法模板: KMP: ; ...
- Caf音频文件混合
一.两个同样时常的caf音频文件,可以通过下面的代码混合 二.代码地址: https://github.com/liqiushui/AudioRecorderCafMix
- 转Delphi中Create(nil),Create(self),Create(Application)区别
Create(nil);//需要自己释放 Create(Self);//当Self释放时自动触发释放 Create(Application);//当Application释放时自动释放 Create( ...
- ZIP文件解压
public class DZip { /// <summary> /// 压缩为ZIP文件 /// </summary> public void Zip(string dir ...
- Activity间切换的动画应用
Activity切换过程中,系统会使用一些默认的动画,显得切换过程不至于太呆板. 在frameworks/base/core/res/res/values下的stlyes.xml文件中有具体的定义各个 ...
- ural 1091. Tmutarakan Exams(容斥原理)
1091. Tmutarakan Exams Time limit: 1.0 secondMemory limit: 64 MB University of New Tmutarakan trains ...
- C#第六天
字符串的处理练习: 课上练习1:接收用户输入的字符串,将其中的字符以与输入相反的顺序输出."abc"→"cba" 方法1: string str = " ...
- Python字符串连接方式
python中有很多字符串连接方式,总结一下: 1 最原始的字符串连接方式:str1 + str22 python 新字符串连接语法:str1, str23 奇怪的字符串方式:str1 str24 % ...
- @ResponseBody返回json时,json数据丢失或者报错
现象: 1.报错:There is a cycle in the hierarchy! 2.返回至前台的json不完整,字段丢失. 错误原因: eg:entity1的属性有list<entiti ...
- 2.2 Xpath-helper (chrome插件) 爬虫、网页分析解析辅助工具
1. Xpath-helper下载 可以直接在chrome浏览器中的扩展程序搜索 Xpath-helper进行添加 也可以直接在http://www.chromein.com/crx_11654.ht ...