Sed gives: sed: can't read : No such file or directory

后端 未结 2 1827
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 18:01

I have the following bash script which repeats for each image found. It needs to iterated over all html, css and js files, and replac

2条回答
  •  感情败类
    2020-12-13 18:34

    (Compiling an answer from comments, the know-how is by melpomene and AlexP.)

    What is that '' after sed -i?

    -i means in-place, that is, edit in the file directly.
    -i '' means edit in place a file whose name is the empty string.
    Since there probably is no file whose name is the empty string, sed complains that it cannot read it.

    Note 1 platform dependency:
    The syntax of -i is one difference between GNU sed and sed from mac os.

    Note 2 "usual" order of arguments:
    The -e switch to indicate the sed code allows having it in between file names.
    This is a trap (in which I for example got caught embarassingly), by making you trip over your expectations of what you find where in an sed command line.
    It allows
    sed -i filename -e "expression" AnotherFileName
    which is an unintentionally camouflaged version of
    sed -i'NoExtensionGiven' "expression" filename AnotherFileName.

提交回复
热议问题