亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 運行腳本程序出錯 [打印本頁]

作者: lingat242    時間: 2008-12-04 17:29
標(biāo)題: 運行腳本程序出錯
最近剛學(xué)腳本編程,今天寫了一個名為ok的腳本,代碼如下:

echo "do you want to start [y]?"
read answer
answer=`echo "$answer" |awk '{print tolower($1)}'`
case $answer in
n)
        echo "no"
        exit 1
        ;;
*)
    echo "yes"
        ;;
esac


保存后,用chmod設(shè)為可執(zhí)行的,
如果直接執(zhí)行ok則沒問題。

</infor/test>ok
do you want to start [y]?
y
yes

但是如果讓它在后臺運行,也就是用ok&,
執(zhí)行結(jié)果就是:

</infor/test>ok&
[1] 139476
</infor/test>do you want to start [y]?
y
y: Command not found.
[1]  + Suspended (tty input)ok

而且會生成一個Suspended 進(jìn)程。

大家?guī)兔纯礊槭裁磿鲥e。

[ 本帖最后由 lingat242 于 2008-12-4 17:33 編輯 ]
作者: MMMIX    時間: 2008-12-04 17:32
需要和用戶交互的進(jìn)程你放在后臺干嘛?
作者: lingat242    時間: 2008-12-04 17:35
先不說這樣是否合適,先說是否可行,
是不是說如果放在后臺,
那么與用戶交互的操作就不能實現(xiàn)?
作者: MMMIX    時間: 2008-12-04 21:29
原帖由 lingat242 于 2008-12-4 17:35 發(fā)表
是不是說如果放在后臺,
那么與用戶交互的操作就不能實現(xiàn)?
Only foreground processes are allowed to read from or write to the terminal.  Background processes which attempt to read from (write to) the terminal are sent a SIGTTIN (SIGTTOU)  signal  by  the  terminal driver, which, unless caught, suspends the process.

這是 bash 手冊 JOB CONTROL 部分的原話。如果你用其他 shell,查查它的手冊。
作者: emmoblin    時間: 2008-12-04 23:52
謝謝樓上,長見識了
作者: lingat242    時間: 2008-12-05 09:04
學(xué)藝不精,
多謝賜教!!

不過應(yīng)該是不能“read from the terminal ”,
但是能夠“write to the terminal ”吧?!

[ 本帖最后由 lingat242 于 2008-12-5 10:41 編輯 ]




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2