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

Chinaunix

標(biāo)題: 關(guān)于$() 和 ` `為什么結(jié)果不一樣 [打印本頁(yè)]

作者: 農(nóng)民伯伯丶    時(shí)間: 2015-11-12 09:14
標(biāo)題: 關(guān)于$() 和 ` `為什么結(jié)果不一樣
INPUT_FILE=INPUT_FILE_${BillIndex}_$i                      #BillIndex 和i都是變量

eval INPUT_FILE=`echo \$$INPUT_FILE`

結(jié)果 >>>>

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


$() 和 ` `有什么區(qū)別呢?之前一直以為是一樣的
作者: lgfang    時(shí)間: 2015-11-12 10:05
本帖最后由 lgfang 于 2015-11-12 10:05 編輯

` ` 更多shell支持,但不如$()好用。后者可以嵌套,不需要額外的轉(zhuǎn)義;而且也不容易寫(xiě)錯(cuò)、看錯(cuò)。好多字體里前者和單引號(hào)很難區(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/
作者: 農(nóng)民伯伯丶    時(shí)間: 2015-11-12 10:32
回復(fù) 2# lgfang

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

   
作者: tc1989tc    時(shí)間: 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] (請(qǐng)問(wèn)怎么理解反斜杠保留了他的字面意思??) 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ù)制代碼

作者: tc1989tc    時(shí)間: 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.
(請(qǐng)問(wèn)怎么理解反斜杠保留了他的字面意思啊??) 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.
作者: 農(nóng)民伯伯丶    時(shí)間: 2015-11-12 11:06
回復(fù) 5# tc1989tc


    謝謝了先,這個(gè)是man 什么可以看到的,英語(yǔ)太水了,能幫忙解釋下不,拿去谷歌翻譯也沒(méi)看明白
作者: yjh777    時(shí)間: 2015-11-12 11:25
應(yīng)該是 $() 里面的 \ 在第一遍解析展開(kāi)時(shí)不做處理

    $() 里面的所有字符串應(yīng)該原樣傳遞給sub shell進(jìn)行解析處理
作者: 農(nóng)民伯伯丶    時(shí)間: 2015-11-12 21:50
回復(fù) 7# yjh777

感謝分析

   




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2