サブシェルでプロセスを終了する方法

サブシェルでプロセスを終了する方法

以下のbash機能があります。

listen_to_thing(){

    cat /tmp/srv-output | while read line; do
      echo "catted: $line"
      if [[ "$line" == 'EOF' ]]; then
         exit 0;  ## I want to exit out of the function upon this event
      fi
    done;

}

キーワードを受け取ったら、catプロセスを終了してbash機能を完了したいと思います。コマンドラインでSIGINTを使用してbash機能を終了できますが、読み取りループ内でプログラム的にbash機能を終了する方法はありますか?

ベストアンサー1

ファイルがありませんcat。すべてが正常です。

listen_to_thing() {
    while read line; do
        echo "read: $line"
        case "$line" in
            EOF) return 0 ;;    # Return out of the function upon this event
        esac
    done </tmp/srv-output
}
  • $line埋め込みファイルと終了したばかりのファイルを区別するには、EOFゼロ以外の状態を返すだけです。

おすすめ記事