現在のプロンプト行を含むファイルにリダイレクト

現在のプロンプト行を含むファイルにリダイレクト

リダイレクトされたコマンド自体を出力ファイルリダイレクトにどのように含めることができますか?例えば

echo "hello!">output.txt

私が望む出力ファイルの内容は次のとおりです。

echo "hello!">output.txt
hello!

ベストアンサー1

これには2つのうちの1つが必要な場合があります。

  1. 使用teeecho端末とファイルに転送された結果を取得します。

    $ echo 'hello!' | tee output
    hello!
    $ cat output
    hello!
    
  2. script完全な端末セッションをキャプチャするには:

    $ script
    Script started, output file is typescript
    $ echo 'hello!' >output
    $ cat output
    hello!
    $ exit
    Script done, output file is typescript
    
    $ cat typescript
    Script started on Sat Nov 10 15:15:06 2018
    $ echo 'hello!' >output
    $ cat output
    hello!
    $ exit
    
    Script done on Sat Nov 10 15:15:37 2018
    

これがあなたが要求したものではない場合は、質問を明確にしてください。

おすすめ記事