結果を実行せずにシェルスクリプトからエコーする方法

結果を実行せずにシェルスクリプトからエコーする方法

このコードを使用して、指定された変更リストに開いているすべてのファイルを印刷します。

while read line; do
    echo "$line"
done < `p4 opened -c $changelist`

ただし、対応する行も実行され、次のエラーが発生します。

./do.sh: line 7: //perforce/a.js#24 - edit change 353 (text) by user1: No such file or directory

私が望む出力は次のとおりです。

//perforce/a.js#24 - edit change 353 (text) by user1

ベストアンサー1

そしてそして プロセスの置き換え:

while IFS= read -r line; do
    echo "$line"
done < <(p4 opened -c $changelist)

バラよりhttp://mywiki.wooledge.org/ProcessSubstitutionそしてhttp://mywiki.wooledge.org/BashFAQ/024

これらのシェルの1つを使用しない場合(Joseph R.がコメントで述べたように)、単純なパイプを使用してください。

p4 opened -c $changelist | while IFS= read -r line; do
    echo "$line"
done

おすすめ記事