亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2139 | 回復(fù): 5
打印 上一主題 下一主題

[其他] 求教: linux 中 [] 、[[]]和(())區(qū)別。循環(huán)結(jié)構(gòu)中的返回值 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2013-01-04 11:11 |只看該作者 |倒序瀏覽
之前提了幾個問題。幾位前輩也給了一些指教。
其實論壇里的基礎(chǔ)教程什么的我都看過,shell編程的書也在看,不過可能是因為理解不夠深刻的原因吧,還是有些混亂...

我看到的表示判斷的方式是: test expression或者 [ expression ]。
剛才又在baidu里又看到了 [[ expression ]] 的用法。

之前blackold兄又提到判斷不只有[ ]的方式,(())也可以。

我在while循環(huán)等處也經(jīng)?吹 (())、[]、[[]]的交雜使用。但是卻沒有看到對這些格式的解釋。

我以前以為 for (( expr1; expr2; expr3 ))是for循環(huán)本身獨有的語法結(jié)構(gòu),這么說來...莫非不是?莫非(( ; ; ))本身即帶有判斷功能?

我的理解是while、if、for等獲取的都是return value而不是value,這點與C不同。不知道各位前輩認為這么理解是否正確。
因為我嘗試用while 1結(jié)果出錯了。


謝謝

論壇徽章:
60
20周年集字徽章-20	
日期:2020-10-28 14:04:3015-16賽季CBA聯(lián)賽之北京
日期:2016-07-06 15:42:0715-16賽季CBA聯(lián)賽之同曦
日期:2016-06-12 10:38:0915-16賽季CBA聯(lián)賽之佛山
日期:2016-05-27 11:54:56黃金圣斗士
日期:2015-12-02 11:44:35白銀圣斗士
日期:2015-11-25 14:32:43白銀圣斗士
日期:2015-11-23 12:53:352015亞冠之布里斯班獅吼
日期:2015-10-21 16:55:482015亞冠之首爾
日期:2015-09-01 16:46:052015亞冠之德黑蘭石油
日期:2015-08-31 11:39:192015亞冠之薩濟拖拉機
日期:2015-08-28 21:06:5315-16賽季CBA聯(lián)賽之廣東
日期:2016-07-12 14:58:53
2 [報告]
發(fā)表于 2013-01-04 11:19 |只看該作者

論壇徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亞冠之浦和紅鉆
日期:2015-06-23 19:10:532015亞冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16賽季CBA聯(lián)賽之山東
日期:2016-01-31 18:25:0515-16賽季CBA聯(lián)賽之四川
日期:2016-02-16 16:08:30程序設(shè)計版塊每日發(fā)帖之星
日期:2016-06-29 06:20:002017金雞報曉
日期:2017-01-10 15:19:5615-16賽季CBA聯(lián)賽之佛山
日期:2017-02-27 20:41:19
3 [報告]
發(fā)表于 2013-01-04 13:56 |只看該作者
樓主,既然精通C可以用cshell

論壇徽章:
0
4 [報告]
發(fā)表于 2013-01-04 14:41 |只看該作者
回復(fù) 3# waker


    帽子兄。能否幫忙解答一下呢?

“我在while循環(huán)等處也經(jīng)?吹 (())、[]、[[]]的交雜使用。但是卻沒有看到對這些格式的解釋。

我以前以為 for (( expr1; expr2; expr3 ))是for循環(huán)本身獨有的語法結(jié)構(gòu),這么說來...莫非不是?莫非(( ; ; ))本身即帶有判斷功能?

我的理解是while、if、for等獲取的都是return value而不是value,這點與C不同。不知道各位前輩認為這么理解是否正確。
因為我嘗試用while 1結(jié)果出錯了。”


[]  [[]]  (()) 分別是怎么作為判斷功能的,Shell中還有其他的判斷功能嗎? (除了test)
另外我的這個理解是否正確呢?

謝謝

論壇徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年紀(jì)念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役紀(jì)念章
日期:2022-04-24 14:33:24
5 [報告]
發(fā)表于 2013-01-04 14:44 |只看該作者
打開ABS,看看第 81 頁。

Advanced Bash-Scripting Guide 3.9.1 中文版.pdf
http://www.72891.cn/thread-1610033-1-1.html

論壇徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亞冠之浦和紅鉆
日期:2015-06-23 19:10:532015亞冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16賽季CBA聯(lián)賽之山東
日期:2016-01-31 18:25:0515-16賽季CBA聯(lián)賽之四川
日期:2016-02-16 16:08:30程序設(shè)計版塊每日發(fā)帖之星
日期:2016-06-29 06:20:002017金雞報曉
日期:2017-01-10 15:19:5615-16賽季CBA聯(lián)賽之佛山
日期:2017-02-27 20:41:19
6 [報告]
發(fā)表于 2013-01-04 15:08 |只看該作者
回復(fù) 4# yonka


  1. Compound Commands

  2. A compound command is one of the following:
  3. (list)
  4. list is executed in a subshell environment (see COMMAND EXECUTION ENVIRONMENT below). Variable assignments and builtin commands that affect the shell's environment do not remain in effect after the command completes. The return status is the exit status of list.

  5. { list; }
  6. list is simply executed in the current shell environment. list must be terminated with a newline or semicolon. This is known as a group command. The return status is the exit status of list. Note that unlike the metacharacters ( and ), { and } are reserved words and must occur where a reserved word is permitted to be recognized. Since they do not cause a word break, they must be separated from list by whitespace or another shell metacharacter.
  7. ((expression))
  8. The expression is evaluated according to the rules described below under ARITHMETIC EVALUATION. If the value of the expression is non-zero, the return status is 0; otherwise the return status is 1. This is exactly equivalent to let "expression".
  9. [[ expression ]]
  10. Return a status of 0 or 1 depending on the evaluation of the conditional expression expression. Expressions are composed of the primaries described below under CONDITIONAL EXPRESSIONS. Word splitting and pathname expansion are not performed on the words between the [[ and ]]; tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution, and quote removal are performed. Conditional operators such as -f must be unquoted to be recognized as primaries.
  11. When used with [[, The < and > operators sort lexicographically using the current locale.

  12. When the == and != operators are used, the string to the right of the operator is considered a pattern and matched according to the rules described below under Pattern Matching. If the shell option nocasematch is enabled, the match is performed without regard to the case of alphabetic characters. The return value is 0 if the string matches (==) or does not match (!=) the pattern, and 1 otherwise. Any part of the pattern may be quoted to force it to be matched as a string.

  13. An additional binary operator, =~, is available, with the same precedence as == and !=. When it is used, the string to the right of the operator is considered an extended regular expression and matched accordingly (as in regex(3)). The return value is 0 if the string matches the pattern, and 1 otherwise. If the regular expression is syntactically incorrect, the conditional expression's return value is 2. If the shell option nocasematch is enabled, the match is performed without regard to the case of alphabetic characters. Any part of the pattern may be quoted to force it to be matched as a string. Substrings matched by parenthesized subexpressions within the regular expression are saved in the array variable BASH_REMATCH. The element of BASH_REMATCH with index 0 is the portion of the string matching the entire regular expression. The element of BASH_REMATCH with index n is the portion of the string matching the nth parenthesized subexpression.

  14. Expressions may be combined using the following operators, listed in decreasing order of precedence:

  15. ( expression )
  16. Returns the value of expression. This may be used to override the normal precedence of operators.

  17. ! expression
  18. True if expression is false.

  19. expression1 && expression2
  20. True if both expression1 and expression2 are true.

  21. expression1 || expression2
  22. True if either expression1 or expression2 is true.

  23. The && and || operators do not evaluate expression2 if the value of expression1 is sufficient to determine the return value of the entire conditional expression.
  24. for name [ [ in [ word ... ] ] ; ] do list ; done
  25. The list of words following in is expanded, generating a list of items. The variable name is set to each element of this list in turn, and list is executed each time. If the in word is omitted, the for command executes list once for each positional parameter that is set (see PARAMETERS below). The return status is the exit status of the last command that executes. If the expansion of the items following in results in an empty list, no commands are executed, and the return status is 0.
  26. for (( expr1 ; expr2 ; expr3 )) ; do list ; done
  27. First, the arithmetic expression expr1 is evaluated according to the rules described below under ARITHMETIC EVALUATION. The arithmetic expression expr2 is then evaluated repeatedly until it evaluates to zero. Each time expr2 evaluates to a non-zero value, list is executed and the arithmetic expression expr3 is evaluated. If any expression is omitted, it behaves as if it evaluates to 1. The return value is the exit status of the last command in list that is executed, or false if any of the expressions is invalid.
  28. select name [ in word ] ; do list ; done
  29. The list of words following in is expanded, generating a list of items. The set of expanded words is printed on the standard error, each preceded by a number. If the in word is omitted, the positional parameters are printed (see PARAMETERS below). The PS3 prompt is then displayed and a line read from the standard input. If the line consists of a number corresponding to one of the displayed words, then the value of name is set to that word. If the line is empty, the words and prompt are displayed again. If EOF is read, the command completes. Any other value read causes name to be set to null. The line read is saved in the variable REPLY. The list is executed after each selection until a break command is executed. The exit status of select is the exit status of the last command executed in list, or zero if no commands were executed.
  30. case word in [ [(] pattern [ | pattern ] ... ) list ;; ] ... esac
  31. A case command first expands word, and tries to match it against each pattern in turn, using the same matching rules as for pathname expansion (see Pathname Expansion below). The word is expanded using tilde expansion, parameter and variable expansion, arithmetic substitution, command substitution, process substitution and quote removal. Each pattern examined is expanded using tilde expansion, parameter and variable expansion, arithmetic substitution, command substitution, and process substitution. If the shell option nocasematch is enabled, the match is performed without regard to the case of alphabetic characters. When a match is found, the corresponding list is executed. If the ;; operator is used, no subsequent matches are attempted after the first pattern match. Using ;& in place of ;; causes execution to continue with the list associated with the next set of patterns. Using ;;& in place of ;; causes the shell to test the next pattern list in the statement, if any, and execute any associated list on a successful match. The exit status is zero if no pattern matches. Otherwise, it is the exit status of the last command executed in list.
  32. if list; then list; [ elif list; then list; ] ... [ else list; ] fi
  33. The if list is executed. If its exit status is zero, the then list is executed. Otherwise, each elif list is executed in turn, and if its exit status is zero, the corresponding then list is executed and the command completes. Otherwise, the else list is executed, if present. The exit status is the exit status of the last command executed, or zero if no condition tested true.
  34. while list; do list; done
  35. until list; do list; done
  36. The while command continuously executes the do list as long as the last command in list returns an exit status of zero. The until command is identical to the while command, except that the test is negated; the do list is executed as long as the last command in list returns a non-zero exit status. The exit status of the while and until commands is the exit status of the last do list command executed, or zero if none was executed.

復(fù)制代碼
都是大家約定的東西,至于為什么,俺沒能力關(guān)心
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP