[英]How do I send more output after a user prompt with bash script
我正在处理bash脚本,并且想在脚本主菜单的底部放一个免责声明。
我需要回显几个菜单选项供用户选择。 阅读用户输入。
我的问题是读取停止,并等待用户输入。是否可以提示用户,同时在屏幕底部(用户提示下方)显示免责声明?
如果应该从多个菜单选项中选择用户,则可能需要使用select
而不是read
。
答案的处理更加轻松快捷,并且降低了用户误输入的风险。
(我本可以对此发表评论,但我可以)
我不确定我是否完全理解您的问题,但是您可以像这样在屏幕底部写下免责声明,然后返回顶部以要求输入...
#!/bin/bash
lines=$(tput lines) # Get number of lines in Terminal
while :; do
tput clear # Clear screen
echo # Leave space for prompt
echo
echo Option 1:
echo Option 2:
echo Option 3:
echo
tput cup $lines 0 # Put cursor to foot of screen
tput smso # Enable BOLD (Stand Out Mode)
echo -n Disclaimer - this may be rubbish.
tput rmso # Disable BOLD (Remove Stand Out Mode)
tput cup 0 0 # Put cursor to top of screen
echo -n Enter your choice:
read x
done
顺便按Ctrl-C
退出。
注意:
以下内容可能对您有用:
tput sc
保存光标位置
tput rc
恢复光标位置
如果您像这样使用echo -e
,也可以将tput
命令嵌入echo
语句中:
echo -e "Plain $(tput smso)Bold$(tput rmso) Plain"
平原Bold
平原
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.