bash `sed -i -e` 和 `sed -ie` 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43582494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:03:37  来源:igfitidea点击:

What is the difference between `sed -i -e` and `sed -ie`?

bashunixsed

提问by mrgloom

What is the difference between sed -i -eand sed -ie? It's not very clear from help sed --help

sed -i -e和 和有什么不一样sed -ie?帮助不是很清楚 sed --help

  -e script, --expression=script
                 add the script to the commands to be executed

In second case it creates some backup file?

在第二种情况下,它会创建一些备份文件吗?

In general Unix utils do not permit to combine flags?

一般来说,Unix utils 不允许组合标志?

Just an example to show what is happening:

只是一个例子来说明正在发生的事情:

echo "bla" > 1.txt
cat 1.txt
bla
sed -i -e 's:bla:blakva:g' 1.txt
cat 1.txt
blakva
sed -ie 's:bla:blakva:g' 1.txt
cat 1.txt
blakvakva
*Note: also 1.txte is created, containing
cat 1.txte
blakva

Also not still sure what is -edoing in my example, because sed -i 's:bla:blakva:g' 1.txtworks too.

也不确定-e在我的例子中做了什么,因为sed -i 's:bla:blakva:g' 1.txt也有效。

采纳答案by sat

When you give sed -i -e, sedsees two options.

当你给sed -i -esed看到两个选项。

But, When you give sed -ie, sedsees -ioption only with suffixas e. That is the reason you got file backup with esuffix.

但是,当您给 时sed -ie,只能sed看到-i选项suffixas e。这就是您获得带e后缀的文件备份的原因。

From man sed:

-i[SUFFIX], --in-place[=SUFFIX]

edit files in place (makes backup if SUFFIX supplied)

来自man sed

-i[后缀], --in-place[=后缀]

就地编辑文件(如果提供 SUFFIX,则进行备份)

回答by jehutyy

Option -imeans that it modify in-place the file you are sed-ing. Otherwise sedjust show what modification were done. If you add a suffix after -i(e.g -i.bck) it will backup your input file then add the suffix provided.

选项-i意味着它就地修改您正在 sed-ing 的文件。否则sed只显示进行了哪些修改。如果您在-i(例如-i.bck)之后添加后缀,它将备份您的输入文件,然后添加提供的后缀。

Option -eallow you to provide sed script instead of command line arguments.

选项-e允许您提供 sed 脚本而不是命令行参数。