鍍金池/ 問(wèn)答/Linux/ shell 命令求解

shell 命令求解

mvn-entrypoint.sh

find /usr/share/maven/ref/ -type f -exec bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log" \;

想問(wèn)一下,上面這個(gè)命令中 最后的那個(gè) _ (下劃線) 是什么意思?

-# Updated on 2017.12.12 17:24

另外,bash -c 指定的命令,$1 與 $2,和 _ {} "$log" 是什么映射關(guān)系?
我這邊理解是 $1 --> {} 的實(shí)際結(jié)果,$2 --> $log 的實(shí)際結(jié)果,然后就不知道 _ 在這邊是做什么的了

-# Updated on 2017.12.13 17:02
看了 vvpale 的回答之后,又去看了一下 man bash,命令說(shuō)明:
-c string If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.

回答
編輯回答
司令

其實(shí)這個(gè)_沒(méi)有特殊意義,這個(gè)完全是為了滿足bash的-c選項(xiàng)對(duì)位置參數(shù)的語(yǔ)法規(guī)定:
選項(xiàng)-c 后面的字符串將作為命令交給bash執(zhí)行,當(dāng)這個(gè)字符串后面還有參數(shù)時(shí),這些參數(shù)將作為位置變量傳遞給這個(gè)命令,從$0開(kāi)始
于是,對(duì)于命令 bash -eu -c 'copy_reference_file /usr/share/maven/ref/ "$1" "$2"' _ {} "$log"來(lái)說(shuō),內(nèi)部命令 copy_re... $1 $2 后面的三個(gè)單詞都將作為位置變量,其中$0的值為_(kāi),$1的值是{}的結(jié)果,$2的值是$log的結(jié)果。
可將_換成別的word嘗試一下:bash -c 'echo $1 $2' "adsdads xxoo" "hello" "world"

2018年8月20日 23:37
編輯回答
做不到

應(yīng)該是 bash 的參數(shù)。

clipboard.png

2017年3月30日 20:21