flow control: if, and the 'test expression'

if [ commands/test expression ]; then

    commands

elif [ commands /test expression ]; then

    commands

else

    commands

fi

Test Expression in IF : is envaluated either true or false; if true, execute following commands, then exit 0; elif false, exit 1 directly, no any commands executed;

1. String Test Expression

string test expressions

2. File Test Expression

file test expressions
Integer expressions

Advanced Test

1).  syntax [[  expression  ]] , this advanced test supports a new string expression:

    string1 =~ regex

### the string operator ' =~ ' means ' string1 matchs the regular expression regex';

this '[[   ]]' still supports 'pattern matching' with operator '==', examples:

Sting [[ ]]

Advanced test for integer:  synx  ((   )), used to perform arithmetic truth test; it's Truth if the expression result is non-zero.

a=1

(( b = a + 1 )) 

echo $b   ### 2

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,465评论 19 139
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,776评论 0 10
  • 忘了那首诗的名字 那里有琉璃的景 风很轻柔 在这个栀子花开的季节 多想附和那首诗 采一抹它的清香 都市的钢铁丛林 ...
    王巧乐阅读 195评论 0 1

友情链接更多精彩内容