[英]Why I can't add lines with “echo >>” from bash script?
I have got the code: 我有代码:
#!/bin/bash
myParam='/linuxcoe'
myConfigFile='/etc/exports'
if grep -q myParam myConfigFile
then echo "myParam string exist!"
else
echo "Did not find string, adding"
echo "/linuxcoe *" >> myConfigFile
fi
But it don't work from bash script, in config we don't have new lines. 但这在bash脚本中不起作用,在配置中我们没有换行。 echo "/linuxcoe *" >> /etc/exports from console with root works good, but don't work from script, started by root.
从具有根目录的控制台回显“ / linuxcoe *” >> / etc / exports效果很好,但不能从根目录启动的脚本运行。 Why?
为什么? How to solve it?
怎么解决呢? How to add strings to config file?
如何添加字符串到配置文件?
You mean echo "/linuxcoe *" >> "$myConfigFile"
. 您的意思是
echo "/linuxcoe *" >> "$myConfigFile"
。 Your existing script is creating a file named myCOnfigFile
. 您现有的脚本正在创建一个名为
myCOnfigFile
的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.