StupidBeauty
Read times:427Posted at:Fri Jun 8 18:30:16 2012
- no title specified

转载:3.4. 条件判断

bash中的test语句是使用方括号加分号括起来的,注意方括号与其中的条件之间要加空格。

http://imghch.com/doc/bk03ch03s04.html

亮点:

Example 3.9. if-then-else 来计算表达式

[user@domain ~]$ function mycalc ()

> {

> local x

> if [ $# -lt 1 ]; then

> echo "This function evaluates arithmetic for you if you give it some"

> elif (( $* )); then

> let x="$*"

> echo "$* = $x"

> else

> echo "$* = 0 or is not an arithmetic expression"

> fi

> }

[user@domain ~]$ mycalc 3 + 4

3 + 4 = 7

[user@domain ~]$ mycalc 3 + 4**3

3 + 4**3 = 67

[user@domain ~]$ mycalc 3 + (4**3 /2)

-<application>Bash</application>: syntax error near unexpected token `('

[user@domain ~]$ mycalc 3 + "(4**3 /2)"

3 + (4**3 /2) = 35

[user@domain ~]$ mycalc xyz

xyz = 0 or is not an arithmetic expression

[user@domain ~]$ mycalc xyz + 3 + "(4**3 /2)" + abc

xyz + 3 + (4**3 /2) + abc = 35

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands

 
Recent comments
2017年4月~2019年4月垃圾短信排行榜Posted at:Thu Sep 26 04:51:48 2024
Qt5.7文档翻译:QWebEngineCookieStore类,QWebEngineCookieStore ClassPosted at:Fri Aug 11 06:50:35 2023盲盒kill -9 18289 Grebe.20230517.211749.552.mp4