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. PAT (Advanced Level) 1086. Tree Traversals Again (25)

    入栈顺序为先序遍历,出栈顺序为中序遍历. #include<cstdio> #include<cstring> #include<cmath> #include&l ...

  2. bzoj 5091: [Lydsy0711月赛]摘苹果

    5091: [Lydsy0711月赛]摘苹果 Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 148  Solved: 114[Submit][Statu ...

  3. Halcon导出的cpp, VC++环境配置

    方式一: 1.project ->设置(Alt+F7) -> C/C++ ->分类:预处理器 ->附加包括路径   添加:$(HALCONROOT)/include,$(HAL ...

  4. CodeForces 321A Ciel and Robot(数学模拟)

    题目链接:http://codeforces.com/problemset/problem/321/A 题意:在一个二维平面中,開始时在(0,0)点,目标点是(a.b),问能不能通过反复操作题目中的指 ...

  5. linux系统之shell编程-正則表達式

    shell编程正則表達式: 1:元字符   [ ]  .   *  ? + ( )  |  {  }  ^  $ 2 : [a-z0-9]  表示匹配随意数字和字母的一个 3 :  [^a-z]    ...

  6. python实现的websocket总结 —— wspy

    之前曾有php版的websocket封装包.见Websocket--php实战,近期使用python做一些功能,须要用到对websocket的操作,因此,參照之前的实现,实现了这个python版本号. ...

  7. App反编译二次打包常见问题处理

    1.二次打包时报错:Error retrieving parent for item: No resource found that matches the given name 如: D:\用户文件 ...

  8. mybatis 动态curd

    xml <select id="selectByCondition" parameterType="com.oracle.pojo.Student" re ...

  9. 线程、SMP、微内核

  10. 关于CAShapeLayer

    关于CAShapeLayer 内容大纲: CAShapeLayer简介 贝塞尔曲线与CAShapeLayer的关系 strokeStart和strokeEnd 动画 用CAShapeLayer实现进度 ...