<% tp.file.title %>

报错

1
2
unknown escape sequence:
-:16:21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
global: {
test: "111"
}

data: """
\(global.test)
#!/bin/sh
echo -e "\n 追加镜像仓库映射到/etc/hosts文件 "
# 要检查并追加的IP和主机名
IP="1.1.1.1"
HOSTNAME="abc"
# 要搜索的字符串
search_string="$IP $HOSTNAME"

# 使用grep检查字符串是否存在,并且没有被注释掉
if ! grep -E "^[^#]\s*$search_string" /etc/hosts; then
echo "$search_string" | sudo tee -a /etc/hosts > /dev/null
echo "已添加 $search_string 到 /etc/hosts"
else
echo "$search_string 已在 /etc/hosts 中找到,无需添加"
fi

"""

image.png

解决方案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
global: {
test: "111"
}

data: """
\(global.test)
#!/bin/sh
echo -e "\n 追加镜像仓库映射到/etc/hosts文件 "
# 要检查并追加的IP和主机名
IP="1.1.1.1"
HOSTNAME="abc"
# 要搜索的字符串
search_string="$IP $HOSTNAME"

# 使用grep检查字符串是否存在,并且没有被注释掉
if ! grep -E "^[^#]\\s*$search_string" /etc/hosts; then
echo "$search_string" | sudo tee -a /etc/hosts > /dev/null
echo "已添加 $search_string 到 /etc/hosts"
else
echo "$search_string 已在 /etc/hosts 中找到,无需添加"
fi

"""

data2: #"""
\(global.test)
#!/bin/sh
echo -e "\n 追加镜像仓库映射到/etc/hosts文件 "
# 要检查并追加的IP和主机名
IP="1.1.1.1"
HOSTNAME="abc"
# 要搜索的字符串
search_string="$IP $HOSTNAME"

# 使用grep检查字符串是否存在,并且没有被注释掉
if ! grep -E "^[^#]\s*$search_string" /etc/hosts; then
echo "$search_string" | sudo tee -a /etc/hosts > /dev/null
echo "已添加 $search_string 到 /etc/hosts"
else
echo "$search_string 已在 /etc/hosts 中找到,无需添加"
fi

"""#

image.png


<% tp.file.title %>
http://example.com/2023/11/16/cue/【cue语言系列】(202403) unknown escape sequence/
作者
ningan123
发布于
2023年11月16日
许可协议