perl query using -pie

前端 未结 3 614
无人及你
无人及你 2021-01-11 23:47

This works:

perl -pi -e \'s/abc/cba/g\' hellofile

But this does not:

perl -pie \'s/cba/abc/g\' hellofile

3条回答
  •  深忆病人
    2021-01-12 00:01

    The -i flag takes an optional argument (which, if present, must be immediately after it, not in a separate command-line argument) that specifies the suffix to append to the name of the input file for the purposes of creating a backup. Writing perl -pie 's/cba/abc/g' hellofile causes the e to be taken as this suffix, and as the e isn't interpreted as the normal -e option, Perl tries to run the script located in s/cba/abc/g, which probably doesn't exist.

提交回复
热议问题