Bash:運行「set -i」的效果?

Bash:運行「set -i」的效果?

今天,我正在閱讀 的文檔set,當我意識到我的標誌變數 ( ) 包含幫助頁面 ( ) 和上$-未記錄的標誌時help setGNU.org: i
一段時間後我設法找到這一頁其中指出i代表互動的
當然,我嘗試的第一件事就是將其關閉。
運行後set +i$-不再包含i,但除此之外,一切顯然仍然像往常一樣工作。
同樣,放入set -i腳本檔案在運行時也沒有明顯的效果。

所以,我的問題是:將set -i/set +i放入腳本中或在命令列上運行它除了修改$-變數之外實際上還有其他作用嗎?

答案1

顯然,一旦 shell 初始化,在命令列上使用set -i或 的唯一結果就是更改 的值。只有當呼叫建立 shell時,該選項才有意義,在這種情況下,它將強制 shell 進行互動。set +i$--ibash

對 bash 原始程式碼的快速檢查表明,執行期間的互動式檢查引用了全域變量interactive,該變數在初始化序列期間設置,然後不進行修改。僅set [+-]i$-使用forced_interactive全域。 (如果已設定或如 中所述,interactive則將設為 true 。)forced_interactiveman bash

答案2

bash-1.14.7-14 的手冊頁中有 -i 選項的文件。 https://bugzilla.redhat.com/show_bug.cgi?id=1129

   -i        If the -i option is present, the shell is interactive.

互動式 shell 從 tty 上的使用者輸入讀取命令。除此之外,這樣的 shell 會在啟動時讀取啟動檔案、顯示提示並預設啟用作業控制。使用者可以與 shell 互動。執行腳本的 shell 始終是非互動式 shell。

更多資訊請參閱此處:

http://www.tldp.org/LDP/abs/html/intandnonint.html https://unix.stackexchange.com/questions/43385/what-do-you-mean-by-interactive-shell

補充:更多鏈接

關於非登入 shell 的一個非常好的答案

https://askubuntu.com/questions/247738/why-is-etc-profile-not-invoked-for-non-login-shells

互動式 shell 的 bash 手冊

http://www.gnu.org/software/bash/manual/html_node/Interactive-Shell-Behavior.html#Interactive-Shell-Behavior

相關內容