第一行:什麼是''文件?
據help read
,即''
是一個參數傳遞給-d
參數:
-d delim continue until the first character of
DELIM is read, rather than newline
在線路六:什麼空白處做< <(查找)。
這裏有兩個獨立的操作符。有<
,標準I/O重定向操作,隨後是<(...)
構建體,其是特定的bash構建體,其執行過程取代:
Process Substitution
Process substitution is supported on systems that
support named pipes (FIFOs) or the /dev/fd method of naming
open files. It takes the form of <(list) or >(list). The
process list is run with its input or output connected
to a FIFO or some file in /dev/fd...
因此,這是正在發送find
命令的輸出入do
循環。
<是否像往常一樣重定向?如果他們是,那麼重定向到阻止什麼意思?
重定向進入一個循環意味着環路 從stdin
讀取內部的任何命令將從重定向的輸入源中讀取。作爲 的副作用,該循環內的所有內容都在一個子shell中運行,該子shell對變量範圍有 的影響:在循環外部, 循環內設置的變量不可見。
有人可以幫忙解析一下嗎?這是迭代目錄中某種類型文件的正確方法嗎?
爲了記錄在案,我通常會通過管道向find
xargs
, 雖然它的解決方案是最好的做這取決於在一定上你想做什麼 延伸。在你的問題中的兩個例子完全不同的事情,並不清楚你實際上試圖完成 。
但例如:
find $src -maxdepth 1 -name '*.md' -print0 |
xargs -0 -iDOC wc -w DOC
這將在所有*.md
文件運行wc
。 -print0
至find
(和-0
至xargs
)允許該命令正確處理具有嵌入空白的 文件名(例如,This is my file.md
)。如果 你知道你沒有任何這些,你只是做:
find $src -maxdepth 1 -name '*.md' |
xargs -iDOC wc -w DOC
計數的話在所有降價文件,在第一個例子。第二個例子來自這個建議。謝謝你的回答! – denten