From 716422073f103f531f88046848a2db7b5973cded Mon Sep 17 00:00:00 2001 From: baol Date: Wed, 18 Dec 2024 00:03:34 +0800 Subject: [PATCH 1/2] add hosts.sh --- n0.hosts.sh | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 n0.hosts.sh diff --git a/n0.hosts.sh b/n0.hosts.sh new file mode 100755 index 0000000..2df1220 --- /dev/null +++ b/n0.hosts.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# 定义要添加的内容 +HOSTS_CONTENT=$(cat < /dev/null + echo "Entries added successfully." +else + echo "Entries already exist in /etc/hosts. Skipping..." +fi From 9dbb28d168d75814f4204123689c13604a3119c9 Mon Sep 17 00:00:00 2001 From: baol Date: Wed, 18 Dec 2024 00:08:47 +0800 Subject: [PATCH 2/2] fix bug --- n0.hosts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/n0.hosts.sh b/n0.hosts.sh index 2df1220..d39d0f9 100755 --- a/n0.hosts.sh +++ b/n0.hosts.sh @@ -65,7 +65,7 @@ EOL ) # 检查 /etc/hosts 中是否已经存在这些条目 -if ! grep -Fxq "$HOSTS_CONTENT" /etc/hosts; then +if ! grep -Fxf <(echo "$HOSTS_CONTENT") /etc/hosts > /dev/null; then echo "Adding entries to /etc/hosts..." echo "$HOSTS_CONTENT" | sudo tee -a /etc/hosts > /dev/null echo "Entries added successfully."