Why a linux redirect truncates the file?

后端 未结 3 1930
情话喂你
情话喂你 2021-01-22 23:31

I have a file called \"test.txt\" like that:

hello world

it is, just a \'hello world\' string. If I use a perl regex:

perl -pe          


        
3条回答
  •  清歌不尽
    2021-01-23 00:02

    It opens the file for writing due to the redirect before the application gets a chance to read from it. Redirect to a temporary file instead, then rename it after.

提交回复
热议问题