在Linux shell编程中,经常会用到判断字符串是否相等,可用于判断字符串是否相等的操作符有‘-eq’(相等), ‘-ne’(不等于), ‘-lt’(小于), ‘-le’(小于或等于), ‘-gt’(大于)或‘-ge’(大于或等于),以及=,==,!=,。

在bash指南中,字母操作符和符号操作符的两端的参数英语表达式不相同,符号操作符用的是string,字母操作符用的是arg。

string1==string2

string1=string2

True if the strings are equal. ‘=’ should be used with the test command for POSIX conformance.

string1!=string2

True if the strings are not equal.

string1

True ifstring1sorts beforestring2lexicographically.

string1>string2

True ifstring1sorts afterstring2lexicographically.

arg1OParg2

OP is one of ‘-eq’, ‘-ne’, ‘-lt’, ‘-le’, ‘-gt’, or ‘-ge’. These arithmetic binary operators return true ifarg1is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal toarg2, respectively.Arg1andarg2may be positive or negative integers.

在实际编程中发现,当用字母操作符,虽然效果与符号操作符相同,但会产生一个错误提示“[[: arg2: syntax error: operand expected (error token is "arg2")”。

如原文为[[ "$1" -eq "" ]] && echo "delete all spaces and comments of specialized file, using with $@ filename" && exit 1

修改为[[ "$1" == "" ]] && echo "delete all spaces and comments of specialized file, using with $@ filename" && exit 1

就不再提示了。

附带一个实用小脚本,用途:grep掉空格和注释符(#),简单实用。#!/bin/bash

# delete all spaces and comments of specialized file, using with $@ filename

[[ "$1" == "" ] && echo "delete all spaces and comments of specialized file, using with $@ filename" && exit 1

grep -v \# $1 | grep -v ^$

添加到操作系统中:cat > delsc.sh <

#!/bin/bash

# delete all spaces and comments of specialized file, using with $@ filename

[[ "\$1" -== "" ]] && echo "delete all spaces and comments of specialized file, using with \$@ filename" && exit 1

grep -v \# \$1 | grep -v ^$

eof

chmod +x ./delsc.sh

\mv delsc.sh /usr/local/bin/delsc

which delsc

cat /usr/local/bin/delsc

用法:delsc filename

linux中eq的作用,Linux shell中比较操作符“==”与“-eq”对比相关推荐

  1. python判断linux中文件是否存在_linux shell 中判断文件、目录是否存在的方法

    本文主要介绍了linux shell 中判断文件.目录是否存在的方法,分享给大家 -e filename 如果 filename存在,则为真 -d filename 如果 filename为目录,则为 ...

  2. linux中感叹号的作用,Linux - 感叹号

    在Linux命令行下令人惊叹的惊叹号(!) ! 符号在 Linux 中不但可以用作否定符号,还可以用来从历史命令记录中取出命令或不加修改的执行之前运行的命令.下面的所有命令都已经在 Bash Shel ...

  3. linux中特殊符号分割,Shell_Linux Shell 中实现字符串切割的几种方法

    我们在shell 脚本编程中,经常需要用到字符串切割,即将字符串切割为一个数组,类似java 中的split 函数,下面对几种常见的方式做一个总结. 参考文章: shell 使用指定的分割符来分割字符 ...

  4. linux 脚本 expected,使用expect实现shell中scp自动输入密码

    使用expect实现shell中scp自动输入密码 前段时间有一个需求,要实现一个自动备份脚本,因为不需要全部备份,所以没有使用rsync,在这里使用scp.因为scp需要输入用户密码,在网上查了好多 ...

  5. 原linux的字符文件作用,linux特殊字符及其作用大全

    1.通配符 ? 匹配单个字符 * 代表所有字符 [abcd] 匹配[]里任意一个字符.4选1 [a-d] [!abcd]  匹配不含[]里任意一个字符的字符.[^abcd] 2.路径相关 ~     ...

  6. linux pushd 不起作用,Linux命令行导航提示:pushd和popd命令的基础

    在本系列的第一部分中,我们通过讨论cd- command的用法来关注Linux中的命令行导航方面. 还讨论了一些其他相关点/概念. 进一步讨论,在本文中,我们将讨论如何使用pushd和popd命令在L ...

  7. linux各种挂载点作用,Linux 挂载点目录及其作用

    Linux 挂载点目录及其作用 Linux 挂载点目录及其作用 什么是挂载点? Linux 使用字母和数字的组合来指代磁盘分区 Linux 是一切皆文件,整个系统都是当做文件来管理,在Windows中 ...

  8. linux 下export的作用,linux export 的作用

    功能说明:设置或显示环境变量.语 法:export [-fnp][变量名称]=[变量设置值]补充说明:在shell中执行程序时,shell会提供一组环境变量.export可新增,修改或删除环境变量,供 ...

  9. linux 系统pwd的作用,linux系统pwd命令的作用

    在Linux系统中有很多命令,用户可以用这些命令创建新目录或者转换到目录.但是用户在转换目录之后,系统没有给出相应提示,所以经过几次转换后用户可能不知道自己所在的目录是哪里.而pwd命令的作用就在这里 ...

最新文章

  1. 指定ASP .NET Core Web应用端口
  2. LeetCode 528. 按权重随机选择(前缀和+二分查找)
  3. tensorflow tfrecoder read write
  4. C#树状图 初始默认选中节点
  5. /etc/resolv.conf文件详解
  6. Flink 生态:Pulsar Connector 机制剖析
  7. logistic回归__基于Python和Numpy函数库
  8. P3690 【模板】Link Cut Tree (动态树)
  9. 关于C#中Thread.Join()的一点理解
  10. java applet_Java Applet 基础
  11. imx6,imx7和am335环境变量配置文件
  12. HIT CSAPP hello的一生
  13. Android补间动画之旋转动画
  14. 俄罗斯FAC认证介绍
  15. Chrome浏览器屏蔽百度推广
  16. 【新型密集采样网络:遥感超分】
  17. IP协议协议--IP分片
  18. Docker集群(一) —— Docker网络及flannel介绍
  19. html图片折叠,CSS 实现 图片鼠标悬停折叠效果
  20. 央视调查:“芯荒”正帮助国产汽车芯片实现零的突破

热门文章

  1. 控制反转( IoC)和依赖注入(DI)
  2. python排序编程,02.编程学习--Python 排序
  3. vue中根据后端接口数据控制按钮的显示与隐藏(手动添加响应式this.$set())
  4. 搜索引擎推广是什么意思?如何采用网络曝光的方式做好搜索引擎推广
  5. Android5g手机,今年唯一小屏安卓5G手机!5.7寸+骁龙765G:真机亮相!
  6. HTML5 Day02 知识点总结
  7. echarts学习——(下)Vue+Echarts构建大数据可视化酷屏展示公司品牌实战项目分享(附源码)
  8. 赚钱小视频autojs脚本分享
  9. 创业公司的管理工具集萃
  10. maya点线面计数_maya2014里的选择点线面隐藏咯.在哪里让它显示出来