【发布时间】:2020-05-10 14:27:55
【问题描述】:
附上代码:
#!/bin/bash
echo 'if [ -f /etc/skel/.bashrc ]; then . /etc/skel/.bashrc; fi' >> ~/.bashrc
echo 'enable -n echo' >> ~/.bashrc
echo "alias cls=\"echo -en '\033c\033[3J'\"" >> ~/.bashrc
echo "alias cmdlist='compgen -c | sort -b'" >> ~/.bashrc
sed -i '/if [ -f /etc/skel/.bashrc ]; then . /etc/skel/.bashrc; fi/d' ~/.bashrc
sed -i '/enable -n echo/d' ~/.bashrc
sed -i "/alias cls=\"echo -en '\033c\033[3J'\"/d" ~/.bashrc
sed -i "/alias cmdlist='compgen -c | sort -b'/d" ~/.bashrc
我期望一个空文件 .bashrc,而不是它包含:
if [ -f /etc/skel/.bashrc ]; then . /etc/skel/.bashrc; fi
alias cls="echo -en '\033c\033[3J'"
为什么?
【问题讨论】:
-
方括号(
[和])在正则表达式中有意义。 -
转义\[不起作用。
-
哈哈哈!你确定吗?或者你遇到了不同的问题?你的正则表达式有更多的问题,比如正则表达式中的斜线。他们告诉表达式在哪里结束,你告诉
sed它在if -f之后结束。更多的东西要逃脱! -
谢谢,34分钟后,我解决了!
标签: bash shell terminal linux-mint