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用项目模板生成项目

    Archetype插件是Maven生成项目的项目模板,项目模板就是一个框,把文件夹这些定好,然后就可以在上开写具体逻辑等等. 最常用的命令: mvn archetype:generate 这个是生成一 ...

  2. C++字符串转数字,数字转字符串

    1. 字符串转数字 如将"32"转为32,将"3.1415"转为3.1415,将"567283"转为567283.使用: //Convert ...

  3. 【转】DSP是什么--DSP是神马东东??

    原文:http://www.eepw.com.cn/article/272908.htm 导读:本文主要介绍的是DSP是什么,不懂得童鞋们快随小编一起学习一下DSP到底是个神马东东吧! 本文引用地址: ...

  4. [cocos2d-x]怎样降低cocos2d-x游戏的耗电量?

    Cocos2d-x游戏的耗电量一直是个让人头疼的问题,一个简单的三消游戏,玩一会手机就热得发烫,更郁闷的是电池消耗非常快.基本上两个小时就能够把电池耗光. 近期又看到一个帖子.有个老外用cocos2d ...

  5. window.onresize 事件笔记

     1.浏览器尺寸变化响应事件 : window.onresize = function(){....} 这里须要注意的是,onresize响应事件处理中.获取到的页面尺寸參数是变更后的參数. // ...

  6. HDU 1060 Leftmost Digit (数学/大数)

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. Linux下mount FreeBSD分区

    假设须要从第二块硬盘复制文件.该硬盘格式化为UFS 2文件系统.怎样mount 由FreeBSD创建的UFS 2文件系统到Ubuntu系统上呢? UFS文件系统广泛的使用在不同的操作系统(比如:HP- ...

  8. 转移iOS App常见问题和回答

    打算转移公司的app,做下转移的记录 怎样转移app官方的一个视频:http://v.youku.com/v_show/id_XNjI0MjQxMzI0.html 以下是apple官方转移常见问题回答 ...

  9. VC编码规范(转)

    1    项目风格   1.1    项目取名     在VC之中,项目名为最后可执行文件名,所以项目名最好以最终的可执行文件名一致. 1.2    项目目录设置     为保证VC项目的备份方便.快 ...

  10. Mac使用小结

    1.修改pip的镜像地址及更新pip https://www.cnblogs.com/techroad4ca/p/5922389.html 2.更新python的库,比如更新six sudo pip ...