2014-09-24 67 views
0

我正在使用bash腳本,並且希望在腳本主菜單的底部放置免責聲明。如何在用戶提示後使用bash腳本發送更多輸出

我需要回顯幾個菜單選項供用戶選擇。 爲用戶輸入做一個閱讀。

我的問題是讀取停止,並等待用戶輸入.. 是否有可能提示用戶,同時也在屏幕底部(在用戶提示下方)顯示免責聲明?

+2

這是可能的,使用類似'ncurses'或ASNI轉義字符,但它是值得的?只需在菜單後顯示免責聲明,但在提示之前。或者承認用戶不太可能閱讀或關注它,只是略過它。 :) – chepner 2014-09-24 22:12:46

回答

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 - 還原光標位置

您還可以嵌入內echotput命令聲明,如果你使用這樣的echo -e

echo -e "Plain $(tput smso)Bold$(tput rmso) Plain" 

平原Bold平原

+0

謝謝!使用tput sc和tput rc - 我可以在屏幕上顯示所有內容,並將光標移回到「promp」行。在爲我的情況調用'read opt'之後。 – 2014-09-28 21:37:15

+0

優秀!樂於助人。 – 2014-09-28 21:42:57

0

如果您的用戶應該從幾個菜單選項中選擇,您可能需要使用select而不是read

答案的處理更加簡單快捷,並降低了用戶誤認的風險。

(我早就把這個作爲一個評論,我會一直能)

相關問題