【发布时间】:2017-02-13 22:36:18
【问题描述】:
编辑:当前代码
#!/bin/bash
check=0
while [ $check -ne 1 ];
do
ping -c 1 192.168.150.1 >> /dev/null
if [ $? -eq 0 ];then
echo -ne "\nClient is up! We will start the web server"
touch /etc/apache2/httpd.conf
echo "ServerName 127.0.0.1" > /etc/apache2/httpd.conf
/etc/init.d/apache2 start
if [ $? -eq 0 ];then
exit 0
fi
else
echo -ne "\nWaiting for client to come online"
sleep 5;
fi
done
我目前正在学习一些 Bash 脚本,我希望能够将其回显到终端,而无需按 Enter 键即可继续使用终端。
例如...如果我回显“我们正在工作”,光标将移动到末尾并等待我按 Enter 键,然后将我返回到可以键入新命令的位置。
server:#
Waiting for client to come online
Waiting for client to come online
Waiting for client to come online
Waiting for client to come online
Waiting for client to come online
Waiting for client to come online
Waiting for client to come online
Waiting for client to come online
Waiting for client to come online <---- Press Enter here
server:#
【问题讨论】:
-
你能给我们看看代码吗?
-
@ArkadiuszDrabczyk 我已经用当前代码编辑了帖子。
-
你为什么要
appending (>>)到NULL对象? -
@123 我没有使用读取,我希望它打印然后继续终端输入,此时它只是回显到命令行中。
-
你是如何运行代码的?我怀疑你是在后台运行它,并且 shell 已经在接受一个新命令;该脚本只是将输出写入您的终端,直到它退出。