パイプ内で変数を割り当てる方法

パイプ内で変数を割り当てる方法

私は bash でワンライナーを構築しています。
スクリプトを作成したり、一時ファイルを作成したりできるオプションがあれば、質問する必要はありません。

後で使用するために、パイプ セットの途中に変数を割り当てる必要があります。

    cat list | awk '{print $1".modifications_to_name"' | (capture $NAME and pass $NAME down pipe) \
    | checkStatus | grep pertinentinfo | cleanupFormatOfPertinentInfo | sendAlert $NAME

答え1

awk に中括弧が欠落していることを無視し、リストに 1 行しか含まれていないと仮定すると、次のようになります。NAME=$( cat list | awk '{print $1".modifications_to_name"') && checkStatus | grep pertinentinfo | cleanupFormatOfPertinentInfo | sendAlert $NAME

複数行のリストを反復処理し、そのたびに name が異なる値に評価されるようにしたい場合は、次のようにします。

while read NAME; do checkStatus | grep pertinentinfo | cleanupFormatOfPertinentInfo | sendAlert $NAME ; done < <(cat list | awk '{print $1".modifications_to_name"')

これはXY質問ですが。

関連情報