英文:
Delete the above line and replace it with other line after the condition become true
问题
read -p "请输入IP地址: " ip
echo -e "\e[5m正在进行ping测试...\e[25m"
ping -c 1 $ip &> /dev/null
if [ $? -eq 0 ]
then
sleep 3
echo -e "\e[1;93m$ip\e[1;39m 可达"
else
echo -e "\e[1;91m$ip\e[1;39m 不可达"
fi
英文:
Please go through the below coding and clarify.
read -p "Enter the ip address: " ip
echo -e "\e[5mpinging...\e[25m"
ping -c 1 $ip &> /dev/null>1
if [ $? -eq 0 ]
then
echo -e "\e[1;93m$ip\e[1;39m is reachable"
else
echo -e "\e[1;91m$ip\e[1;39m is not reachable"
fi
When the above coding is executes, I need the program to wait 3 seconds, then say "IP_ADDR is reachable" also I need to replace the text "pinging..." to "completed" upon execution.
current output:when the above script is executed
needed output:should replace the word "pinging..." with "completed"
答案1
得分: 1
我建议使用\r
转义序列,它表示将光标移到行的第一个字符。
这样将覆盖pinging...
并且它不会显示。
以下是使用这种策略的脚本。
#!/bin/bash
read -p "输入IP地址: " ip
echo -ne "\e[5mpinging...\e[25m\r" # 注意这里的 \r
sleep 1
ping -c 1 $ip &> /dev/null >1
if [ $? -eq 0 ]
then
echo -e "\e[1;93m$ip\e[1;39m 可达"
else
echo -e "\e[1;91m$ip\e[1;39m 不可达"
fi
希望对你有所帮助。
英文:
I would suggest using \r
escape sequence that means, cursor go back to first character of the line.
So this will overwrite pinging...
and it will not appear.
Here is how looks the script with this stategy.
#!/bin/bash
read -p "Enter the ip address: " ip
echo -ne "\e[5mpinging...\e[25m\r" # Note here \r
sleep 1
ping -c 1 $ip &> /dev/null>1
if [ $? -eq 0 ]
then
echo -e "\e[1;93m$ip\e[1;39m is reachable"
else
echo -e "\e[1;91m$ip\e[1;39m is not reachable"
fi
Hope it is helpful.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论