
我正在 bash 中建造一個襯墊。
如果製作腳本或編寫臨時檔案是一種選擇,我就不需要詢問。
我需要在一組管道的中間分配一個變數以供後續使用。
cat list | awk '{print $1".modifications_to_name"' | (capture $NAME and pass $NAME down pipe) \
| checkStatus | grep pertinentinfo | cleanupFormatOfPertinentInfo | sendAlert $NAME
答案1
忽略你的 awk 缺少大括號,並假設 list 包含一行,為什麼不:NAME=$( cat list | awk '{print $1".modifications_to_name"') && checkStatus | grep pertinentinfo | cleanupFormatOfPertinentInfo | sendAlert $NAME
如果您想迭代具有多行的列表,並且每次都將名稱評估為不同的內容:
while read NAME; do checkStatus | grep pertinentinfo | cleanupFormatOfPertinentInfo | sendAlert $NAME ; done < <(cat list | awk '{print $1".modifications_to_name"')
這似乎是一個XY問題雖然。