shell指令碼 互動

2021-07-24 14:48:30 字數 466 閱讀 3888

命令格式

read [-option] [variable...]

常用選項

-n num 從輸入中讀取num個字元

-p prompt 使用prompt字串提示使用者進行輸入

-s 保密模式,在螢幕上不顯示輸入的字元

-t seconds 超時時間

值和變數的三種情況

輸入的值少於變數的情況

#!/bin/bash

ifread -t 10 -sp "enter your press" press;then

echo

-e"\nsecret passphrase" = "$press"

else

echo

-e"\ninput time out" >&2

exit

1fi

shell 基本的互動指令碼

格式 command tag range input1 tag range 說明 這種方法不是所有linux shell下的二進位制 指令碼都能夠使用,如使用makeself生成的.sh就不能用這種方法,這時候可以使用expect。常見錯誤 warning here document at line...

shell習題 使用者互動指令碼

1.要求 寫乙個指令碼,執行後,列印一行提示 please input a number 要求使用者輸入數值,然後列印出該數值,然後再次要求使用者輸入數值。直到使用者輸入 end 停止。2.指令碼答案 root liang 2018 06 21 cat a.sh bin bash while tru...

shell指令碼與Oracle互動方式

shell指令碼呼叫oracle命令 1 直接執行oracle命令 su oracle c export oracle sid echo select sysdate from dual sqlplus grep ora tmp checkdbstatus tmp outnull.tmp 2 1 可...