我正在处理bash脚本,并希望在脚本主菜单的底部放置免责声明。
我需要回显几个菜单选项供用户选择。 读取用户输入。
我的问题是读取停止,并等待用户输入.. 是否可以提示用户,同时还在屏幕底部显示免责声明(在用户提示下方)?
答案 0 :(得分:0)
如果您的用户应该从多个菜单选项中进行选择,您可能需要使用select
代替read
。
答案的处理更容易,更快,并且降低了用户输入错误的风险。
(我会把它作为评论,我能够做到)
答案 1 :(得分:0)
我不确定我是否完全理解您的问题,但您可以在屏幕底部写下免责声明,然后返回顶部请求输入...
#!/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
- 恢复光标位置
如果您使用tput
,也可以在echo
语句中嵌入echo -e
个命令:
echo -e "Plain $(tput smso)Bold$(tput rmso) Plain"
普通Bold
平原