写一些行到一个文件,一个bash脚本 [英] Write some lines to a file with a bash script
本文介绍了写一些行到一个文件,一个bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能写在bash脚本一些行到一个文件?
我想写以下到一个文件〜/ .inputrc文件
\\ E [A:历史记录的搜索向后
\\ E [B:历史记录的搜索前进
\\ E [C:前瞻性CHAR
\\ E [D:向后CHAR
目前我有这个工作,但有些丑陋的方法,我敢肯定,应该有更好的方式。
#!/ bin / sh的
回声\\\\\\ E [A \\:历史记录的搜索向后> 〜/ .inputrc文件
回声\\\\\\ê[B \\:历史记录的搜索转发>> 〜/ .inputrc文件
回声\\\\\\ê[C \\:前向焦炭>> 〜/ .inputrc文件
回声\\\\\\ê研究[D \\:向后字符>> 〜/ .inputrc文件
解决方案
一个稍微简单的方法是:
猫> 〜/ .inputrc文件<< EOF
\\ E [A:历史记录的搜索向后
\\ E [B:历史记录的搜索前进
\\ E [C:前瞻性CHAR
\\ E [D:向后CHAR
EOF
我很好奇,为什么你要做到这一点,虽然。如果你想安装一些特定的文本文件,那么也许你应该创建骨架文件,并将其转储到的/ etc / skel中
。然后,您可以 CP /etc/skel/.inputrc〜/ .inputrc文件
在你的脚本。
How can I write some lines to a file in a bash script?
I want to write the following into a file ~/.inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char
Currently I have this working but somewhat ugly method, and I'm sure there should be a better way.
#!/bin/sh
echo \"\\e[A\": history-search-backward > ~/.inputrc
echo \"\\e[B\": history-search-forward >> ~/.inputrc
echo \"\\e[C\": forward-char >> ~/.inputrc
echo \"\\e[D\": backward-char >> ~/.inputrc
解决方案
A slightly simpler method would be:
cat > ~/.inputrc << "EOF"
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char
EOF
I'm curious why you need to do this though. If you want to setup a file with some specific text, then maybe you should create the skeleton file, and dump it into /etc/skel
. Then, you can cp /etc/skel/.inputrc ~/.inputrc
in your script.
这篇关于写一些行到一个文件,一个bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文