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. echo "/linuxcoe *" >> /etc/exports from console with root works good, but don't work from script, started by root. Why? How to solve it? How to add strings to config file?
You mean echo "/linuxcoe *" >> "$myConfigFile"
. Your existing script is creating a file named myCOnfigFile
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.