Classic technique (escape metacharacters):

if[ \( $g -eq 1-a "$c"="123" \) -o \( $g -eq 2-a "$c"="456" \) ]then echo abc
else echo efg
fi

I tried various tricks with '[[ ... ]]' without success - even escaping the parentheses did not seem to work.


Isn't it a classic question?

I would have thought so. However, there is an alternative, namely:

if[ $g -eq 1-a "$c"="123"]||[ $g -eq 2-a "$c"="456"]then echo abc
else echo efg
fi

Indeed, if you read the 'portable shell' guidelines for the autoconf tool or related packages, this notation - using '||' and '&&' - is what they recommend. I suppose you could even go so far as:

if[ $g -eq 1]&&["$c"="123"]then echo abc
elif[ $g -eq 2]&&["$c"="456"]then echo abc
else echo efg
fi

Where the actions are as trivial as echoing, this isn't bad. When the action block to be repeated is multiple lines, the repetition is too painful and one of the earlier versions is preferable.

[shell test] multiple conditions的更多相关文章

  1. MySQL select from where multiple conditions

    Maybe one of the most used MySQL commands is SELECT, that is the way to stract the information from ...

  2. Linux/shell: Concatenate multiple lines to one line

    $ cat file START Unix Linux START Solaris Aix SCO 1. Join the lines following the pattern START with ...

  3. linux shell unzip multiple zip files

    find . -name "*.result.zip" | xargs -n 1 unzip - -P password -d ../ext_logs

  4. Registering Shell Extension Handlers

    最近在做Windows shell extension 的开发工作,对shell extension handler的注册机制有点疑问,以下摘自MSDN:http://msdn.microsoft.c ...

  5. [Ramda] Filter an Array Based on Multiple Predicates with Ramda's allPass Function

    In this lesson, we'll filter a list of objects based on multiple conditions and we'll use Ramda's al ...

  6. MongoDB - MongoDB CRUD Operations, Query Documents

    Query Method MongoDB provides the db.collection.find() method to read documents from a collection. T ...

  7. systemd service

    Man page systemd.unit SYSTEMD.UNIT(5) systemd.unit SYSTEMD.UNIT(5) NAME systemd.unit - Unit configur ...

  8. Sed - An Introduction and Tutorial by Bruce Barnett

    http://www.grymoire.com/unix/sed.html Quick Links - NEW Sed Commands : label # comment {....} Block ...

  9. 11.Query an Array of Embedded Documents-官方文档摘录

    总结 1.插入数据 db.inventory.insertMany( [ { item: "journal", instock: [ { warehouse: "A&qu ...

随机推荐

  1. Maven打包时过滤测试代码或指定特定的测试类(maven-surefire-plugin)

    1.过滤整个测试代码,可以直接在命令行上指定 mvn clean install -Dmaven.test.skip=true 提示:以上为举例,具体的构建阶段可以自定义,其中maven.test.s ...

  2. PHP实现INT型,SHORT型,STRING转换成BYTE数组

    实现PHP实现INT型,SHORT型,STRING转换成BYTE数组的转化: class Bytes { public static function integerToBytes($val) { $ ...

  3. 使用 Git + Dropbox + SourceTree 做 Source Code Management

    此篇文章主要針對有安裝 XCode 的 Mac 用戶. Git 版本控管工具,作用類似 CVS.Subversion(簡 稱SVN),好處在於 Git 不像 CVS 及 SVN 是屬於集中式的版本控管 ...

  4. Mysql 性能优化20个原则(3)

    12. Prepared Statements Prepared Statements很像存储过程,是一种运行在后台的SQL语句集合,我们可以从使用 prepared statements 获得很多好 ...

  5. 从Nginx源代码谈大写和小写字符转化的最高效代码以及ASCII码表的科学

    说起大写和小写字母转换.大家非常easy想起系统函数是不是,差点儿全部的编程语言都提供了这样的转换函数,可是你有没有想过这背后是怎么实现的? 让你写怎么实现? 我们都知道Nginx是眼下用的最多的Ht ...

  6. Comparable 和 Comparator的理解

    对Comparable 的解释 Comparable是一个排序接口 此接口给实现类提供了一个排序的方法,此接口有且只有一个方法 public int compareTo(T o); compareTo ...

  7. linux 命令之 watch

    watch能够帮你监測一个命令的执行结果,省得你一遍遍的手动执行.在Linux下.watch是周期性的执行下个程序.并全屏显示执行结果.你能够拿他来监測你想要的一切命令的结果变化,比方 tail 一个 ...

  8. sendmessage传递数组

    1.在初始化数组尤其是需要每次都初始化的时候,很多同学使用循环来进行,这样不但速度慢,而且写起来也很长.所以现在提供一个函数来实现这个功能... 原型:extern void *memset(void ...

  9. 电脑突然死机,编译报错dll缺少依赖项

    由于ASP.NET缓存没更新的问题(我的就是这个问题.电脑突然死机导致的). 把这个文件夹下的文件所有删除C:\Windows\Microsoft.NET\Framework\v2.0.50727\T ...

  10. Django 之ORM操作

    1.什么是ORM? 全称关系对象映射Object Relational Mapping(简称ORM),是通过描述面向对象与数据库之间的对应的元数据,将对象持久化的更新到数据库中. 有了ORM,就不需要 ...