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

  免費注冊 查看新帖 |

Chinaunix

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

[文本處理] 關(guān)于$() 和 ` `為什么結(jié)果不一樣 [復(fù)制鏈接]

論壇徽章:
1
15-16賽季CBA聯(lián)賽之同曦
日期:2017-03-19 09:57:50
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2015-11-12 09:14 |只看該作者 |倒序瀏覽
INPUT_FILE=INPUT_FILE_${BillIndex}_$i                      #BillIndex 和i都是變量

eval INPUT_FILE=`echo \$$INPUT_FILE`

結(jié)果 >>>>

改成 eval INPUT_FILE=$(echo \$$INPUT_FILE)
結(jié)果 >>>>


$() 和 ` `有什么區(qū)別呢?之前一直以為是一樣的

論壇徽章:
0
2 [報告]
發(fā)表于 2015-11-12 10:05 |只看該作者
本帖最后由 lgfang 于 2015-11-12 10:05 編輯

` ` 更多shell支持,但不如$()好用。后者可以嵌套,不需要額外的轉(zhuǎn)義;而且也不容易寫錯、看錯。好多字體里前者和單引號很難區(qū)分。

另外,你的需求不需要用eval + $(),直接用所謂的indirect variable reference就行了

  1. # for bash
  2. name_ref=INPUT_FILE_${BillIndex}_$i
  3. INPUT_FILE=${!name_ref}
  4. # for ksh, man nameref
復(fù)制代碼
關(guān)于indirect variable reference的更多信息: http://lgfang.github.io/computer ... indirect-reference/

論壇徽章:
1
15-16賽季CBA聯(lián)賽之同曦
日期:2017-03-19 09:57:50
3 [報告]
發(fā)表于 2015-11-12 10:32 |只看該作者
回復(fù) 2# lgfang

感謝你的方法,不過從我遇到的問題來看,$() 和``除了使用范圍之外,應(yīng)該還有其他差別的

   

論壇徽章:
16
CU十二周年紀念徽章
日期:2013-10-24 15:41:3415-16賽季CBA聯(lián)賽之廣東
日期:2015-12-23 21:21:55青銅圣斗士
日期:2015-12-05 10:35:30黃金圣斗士
日期:2015-11-26 20:42:16神斗士
日期:2015-11-19 12:47:50每日論壇發(fā)貼之星
日期:2015-11-18 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2015-11-18 06:20:002015亞冠之城南
日期:2015-11-10 19:10:492015亞冠之薩濟拖拉機
日期:2015-10-28 18:47:282015亞冠之柏太陽神
日期:2015-08-30 17:21:492015亞冠之山東魯能
日期:2015-07-07 18:48:39摩羯座
日期:2014-08-29 23:01:42
4 [報告]
發(fā)表于 2015-11-12 10:34 |只看該作者
本帖最后由 tc1989tc 于 2015-11-12 10:36 編輯
  1. ...skipping...
  2.               $(command)
  3.        or
  4.               `command`

  5.        Bash performs the expansion by executing command and replacing the command substitu-
  6.        tion with the standard output of the command, with any  trailing  newlines  deleted.
  7.        Embedded  newlines  are  not deleted, but they may be removed during word splitting.
  8.        The command substitution $(cat file) can be replaced by the  equivalent  but  faster
  9.        $(< file).

  10.        [color=Red]When  the  old-style  backquote  form of substitution is used, backslash retains its
  11.        literal meaning except when followed by $, `, or \.  The first  backquote  not  pre-
  12.        ceded by a backslash terminates the command substitution.[/color] (請問怎么理解反斜杠保留了他的字面意思??) When using the $(command)
  13.        form, all characters between the parentheses make up the command; none  are  treated
  14.        specially.

  15.        Command substitutions may be nested.  To nest when using the backquoted form, escape
  16.        the inner backquotes with backslashes.

  17.        If the substitution appears within double quotes, word splitting and pathname expan-
  18.        sion are not performed on the results.
復(fù)制代碼

論壇徽章:
16
CU十二周年紀念徽章
日期:2013-10-24 15:41:3415-16賽季CBA聯(lián)賽之廣東
日期:2015-12-23 21:21:55青銅圣斗士
日期:2015-12-05 10:35:30黃金圣斗士
日期:2015-11-26 20:42:16神斗士
日期:2015-11-19 12:47:50每日論壇發(fā)貼之星
日期:2015-11-18 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2015-11-18 06:20:002015亞冠之城南
日期:2015-11-10 19:10:492015亞冠之薩濟拖拉機
日期:2015-10-28 18:47:282015亞冠之柏太陽神
日期:2015-08-30 17:21:492015亞冠之山東魯能
日期:2015-07-07 18:48:39摩羯座
日期:2014-08-29 23:01:42
5 [報告]
發(fā)表于 2015-11-12 10:36 |只看該作者
...skipping...
              $(command)
       or
              `command`

       Bash performs the expansion by executing command and replacing the command substitu-
       tion with the standard output of the command, with any  trailing  newlines  deleted.
       Embedded  newlines  are  not deleted, but they may be removed during word splitting.
       The command substitution $(cat file) can be replaced by the  equivalent  but  faster
       $(< file).

       When  the  old-style  backquote  form of substitution is used, backslash retains its
       literal meaning except when followed by $, `, or \.  The first  backquote  not  pre-
       ceded by a backslash terminates the command substitution.
(請問怎么理解反斜杠保留了他的字面意思啊??) When using the $(command)
       form, all characters between the parentheses make up the command; none  are  treated
       specially.

       Command substitutions may be nested.  To nest when using the backquoted form, escape
       the inner backquotes with backslashes.

       If the substitution appears within double quotes, word splitting and pathname expan-
       sion are not performed on the results.

論壇徽章:
1
15-16賽季CBA聯(lián)賽之同曦
日期:2017-03-19 09:57:50
6 [報告]
發(fā)表于 2015-11-12 11:06 |只看該作者
回復(fù) 5# tc1989tc


    謝謝了先,這個是man 什么可以看到的,英語太水了,能幫忙解釋下不,拿去谷歌翻譯也沒看明白

論壇徽章:
84
每日論壇發(fā)貼之星
日期:2015-12-29 06:20:00每日論壇發(fā)貼之星
日期:2016-01-16 06:20:00每周論壇發(fā)貼之星
日期:2016-01-17 22:22:00程序設(shè)計版塊每日發(fā)帖之星
日期:2016-01-20 06:20:00每日論壇發(fā)貼之星
日期:2016-01-20 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2016-01-21 06:20:00每日論壇發(fā)貼之星
日期:2016-01-21 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2016-01-23 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2016-01-31 06:20:00數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-01-16 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2016-01-16 06:20:00程序設(shè)計版塊每日發(fā)帖之星
日期:2016-01-14 06:20:00
7 [報告]
發(fā)表于 2015-11-12 11:25 |只看該作者
應(yīng)該是 $() 里面的 \ 在第一遍解析展開時不做處理

    $() 里面的所有字符串應(yīng)該原樣傳遞給sub shell進行解析處理

論壇徽章:
1
15-16賽季CBA聯(lián)賽之同曦
日期:2017-03-19 09:57:50
8 [報告]
發(fā)表于 2015-11-12 21:50 |只看該作者
回復(fù) 7# yjh777

感謝分析

   
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(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