【发布时间】:2017-07-07 07:18:31
【问题描述】:
我正在为 Raspberry Pis 开发一个引导脚本。此脚本确定 Pi 本身是 Model 2 还是 Model 3,并相应地设置其 WiFi 特性。
WiFi 特性的变化放在 /etc/rc.local 文件 (Raspbian) 中,这是通过 bootstrap.sh 脚本完成的。
片段
# model revision number to determine pi
PI_MODEL=$(cat /proc/cpuinfo | grep "Revision" | awk '{print $3}')
case "$PI_MODEL" in
"rev_1A" | "rev_1B")
# Write the wlan config to the rc.local file
cp /etc/rc.local /etc/rc.local.backup
(
cat << 'EOF'
#!/bin/sh -e
iwconfig wlan0 mode ad-hoc essid pi-adhoc channel 6 txpower 0
exit 0
EOF
) > /etc/rc.local
# Case for Pi-2 ends
;;
"pi3_rev1a" | "pi3_rev1b")
# write the wlan config to rc.local file
(
cat << 'EOF'
#!/bin/sh -e
ifconfig wlan0 down
iwconfig wlan0 mode ad-hoc channel 6 essid pi-adhoc txpower 0
ifconfig wlan0 up
exit 0
EOF
) > /etc/rc.local
;;
# case for Pi ends here
esac
但是无论如何都会发出警告:
警告:here-document at line .. 由文件结尾分隔(需要 `EOF')
语法错误:文件意外结束
这里可能出了什么问题?
主要思想是检查 Pi 的类型,然后将相应的 iwconfig 语句添加到 /etc/rc.local 文件中,以便它在重新启动时加入网络。
注意事项:
-
在实际情况下,这只是一个更大的引导脚本的 sn-p,为简洁起见,此处未显示
-
rev_1A等不写是为了简洁
参考资料:
【问题讨论】:
-
这不应该担心。那东西有效。您在我收到的 here-doc 错误和警告中是否有提示/?
-
删除
'EOF'的引号? -
@SiKing 尝试了两种方式。
标签: bash switch-statement heredoc