我正在编写一个脚本,提示用户输入原始 IP,然后输入新 IP。我可以让 sed 从 CLI 工作,但想制作一个脚本,以便用户可以在 Web 服务器上更新自己的公共 IP 以进行访问。
我收到以下错误,但不知道为什么它要寻找 EOF:
./UpdateIP.sh: line 24: unexpected EOF while looking for matching `''
./UpdateIP.sh: line 25: syntax error: unexpected end of file
这是我的脚本:
#!/bin/bash
# This script will change the IP address from x.x.x.x TO y.y.y.y
configs=/root/test.conf
echo "Please enter the IP Address to change:"
# Ask user to input for IP address
read origip
echo "Please enter the NEW IP Address to be changed to:"
read newip
echo "The original IP in the lines below will be changed FROM:
sed 's/$(origip)/$(newip)/' $(configs) | grep $(origip)
echo "TO:"
sed 's/$(origip)/$(newip)/' $(configs) | grep $(newip)
read -p "Press [Enter] key to start updating IP's..."
答案1
您可以使用下面的脚本来更新新的 IP 地址
测试过并且效果很好
script
#!/bin/bash
echo "enter the old ip adress which need to change"
read oldip
echo "enter the new ip adress"
read newip
sed -i "s/$oldip/$newip/g" configfilename