For example: I want to check if "server proxy" exists in the file "aaa",
例如:我想检查“aaa”文件中是否存在“服务器代理”,
- if YES, then there's nothing to be done;
- 如果是,那就没什么可做的了;
- if NOT, then I will add "server proxy" to the last new line of the file "aaa".
- 如果没有,那么我将添加“服务器代理”到文件“aaa”的最后一行。
So how should I use shell command to realize it?
那么我应该如何使用shell命令来实现它呢?
Ps. I think the command tee -a
may give some help to the second step.
我想指挥t -a可能会对第二步有所帮助。
1 个解决方案
#1
2
grep -q "server proxy" aaa || echo "server proxy" >> aaa
#1
2
grep -q "server proxy" aaa || echo "server proxy" >> aaa