小编art*_*iet的帖子

在 Bash 脚本中检查命令的结果

我目前正在阅读“高级 Bash 脚本指南”。有一些脚本在我的机器上无法正常工作:

HNAME=news-15.net # Notorious spammer.
# HNAME=$HOST
# Debug: test for localhost.
count=2 # Send only two pings.
if [[ `ping -c $count "$HNAME"` ]]
then
echo ""$HNAME" still up and broadcasting spam your way."
else
echo ""$HNAME" seems to be down. Pity."
fi
Run Code Online (Sandbox Code Playgroud)

它总是打印$HNAME" still up and broadcasting spam your way.- 即使 IP 地址不存在。有人可以澄清是什么问题吗?

当我使用主机名而不是 IP 地址时,它可以正常工作。

bash shell-script command-substitution

4
推荐指数
1
解决办法
4137
查看次数

标签 统计

bash ×1

command-substitution ×1

shell-script ×1