每当我使用 sed 替换更改时,redis.conf 文件里面是空的
Whenever I use sed to substitute changes, the redis.conf file is empty inside
我知道这听起来很奇怪,但我不明白为什么会这样。所以事情是这样的。我想编写一个 bash 脚本来更改位于 /etc/redis/redis.conf
中的 redis.conf
上的这些变量。脚本是这样的:
sudo sed -e "s/^daemonize no$/daemonize yes/" \
-e "s/^# unixsocket /var/run/redis-server.sock$/unixsocket /var/run/redis/redis.sock/" \
-e "s/^# unixsocketperm 700$/unixsocketperm 770/" \
-e "s/^# maxclients 10000$/maxclients 512/" \
-e "s/^databases 16$/databases 128/" /etc/redis/redis.conf | sudo tee /etc/redis/redis.conf
曾经 运行,我在 sed 上收到一条错误消息,发现没有要更改的替代项。我查看了 /ect/redis/redis.conf
文件,里面什么都没有。没有任何配置。有人可以帮助我了解我做错了什么。我将不胜感激。
问题已解决。代码现在看起来像这样,可以完美满足我的需要。
if [ ! -d "/etc/redis/redis.conf" ]; then
sed -i "s|^# unixsocket /var/run/redis/redis-server.sock$|unixsocket /var/run/redis/redis.sock|
s|^# unixsocketperm 700$|unixsocketperm 770|
s|^# maxclients 10000$|maxclients 512|
s|^databases 16$|databases 128|" /etc/redis/redis.conf
fi
Benjamin W. 对我理解定界符和深入研究 sed
命令很有帮助。我希望这可以帮助正在为他们的环境配置 redis.conf
的其他人。
我知道这听起来很奇怪,但我不明白为什么会这样。所以事情是这样的。我想编写一个 bash 脚本来更改位于 /etc/redis/redis.conf
中的 redis.conf
上的这些变量。脚本是这样的:
sudo sed -e "s/^daemonize no$/daemonize yes/" \
-e "s/^# unixsocket /var/run/redis-server.sock$/unixsocket /var/run/redis/redis.sock/" \
-e "s/^# unixsocketperm 700$/unixsocketperm 770/" \
-e "s/^# maxclients 10000$/maxclients 512/" \
-e "s/^databases 16$/databases 128/" /etc/redis/redis.conf | sudo tee /etc/redis/redis.conf
曾经 运行,我在 sed 上收到一条错误消息,发现没有要更改的替代项。我查看了 /ect/redis/redis.conf
文件,里面什么都没有。没有任何配置。有人可以帮助我了解我做错了什么。我将不胜感激。
问题已解决。代码现在看起来像这样,可以完美满足我的需要。
if [ ! -d "/etc/redis/redis.conf" ]; then
sed -i "s|^# unixsocket /var/run/redis/redis-server.sock$|unixsocket /var/run/redis/redis.sock|
s|^# unixsocketperm 700$|unixsocketperm 770|
s|^# maxclients 10000$|maxclients 512|
s|^databases 16$|databases 128|" /etc/redis/redis.conf
fi
Benjamin W. 对我理解定界符和深入研究 sed
命令很有帮助。我希望这可以帮助正在为他们的环境配置 redis.conf
的其他人。