bash 指令:如何自動輸入安裝過程中稍後出現的選單選項?

bash 指令:如何自動輸入安裝過程中稍後出現的選單選項?

apt-get install -y python-catkin-toolsUbuntu 上,當安裝「tzdata (2020f-0ubuntu0.18.04)」時,您必須輸入時區編號 8(代表地區)和 7(代表城市)。

我怎麼能運行apt-get install -y python-catkin-tools,以便稍後彈出的選單選項在輸入時首先得到8,然後得到7?我已經用##標記了要輸入的數字

apt-get install -y python-catkin-tools

...

Setting up tzdata (2020f-0ubuntu0.18.04) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Configuring tzdata
------------------

Please select the geographic area in which you live. Subsequent configuration questions will narrow this down by presenting a list of cities, representing the time zones in which they are located.

  1. Africa  2. America  3. Antarctica  4. Australia  5. Arctic  6. Asia  7. Atlantic  8. Europe  9. Indian  10. Pacific  11. SystemV  12. US  13. Etc
Geographic area: ##8##

Please select the city or region corresponding to your time zone.

  1. Amsterdam  6. Belgrade    11. Budapest    [shortened...]

Time zone:


Time zone: ##7##

Current default time zone: 'Europe/Berlin'
Local time is now:      Wed Jan 20 22:42:43 CET 2021.
Universal Time is now:  Wed Jan 20 21:42:43 UTC 2021.
Run 'dpkg-reconfigure tzdata' if you wish to change it.

我需要它從 Dockerfile 自動運行,而不要求使用者在安裝過程中輸入時區。我想知道如何將正確的時區放在這裡作為安裝命令的參數,或者作為一個簡單的解決方法,如何強制它使用預設時區。

經過最近的運行,我發現在安裝過程中從 Dockerfile 輸入數字似乎也不起作用。這些條目不會觸發任何內容。

[...]
Setting up tzdata (2021a-0ubuntu0.18.04) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Configuring tzdata
------------------

Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.

  1. Africa      4. Australia  7. Atlantic  10. Pacific  13. Etc
  2. America     5. Arctic     8. Europe    11. SystemV
  3. Antarctica  6. Asia       9. Indian    12. US
Geographic area: 8

7
^C

由於我認為這個問題並非特定於 apt-get 或作業系統,因此我不會將其標記為此類。如果我這裡錯了,請更改。

答案1

在建立 Dockerfile 時,這對我不起作用:

(您仍然可以嘗試一下,也可以使用外部連結)

如果您想要瀏覽工作選單並在選單中手動輸入您選擇的值,則需要一個「控制台設定」(例如帶有 的 gnome-terminal apt-get install -y gnome-terminal)才能開啟終端對話方塊。但我無法讓它運行,可能ssh需要它,請參閱「無法初始化前端:使用 ssh 時的對話框」的答案,這意味著在這種情況下激活終端(TERM)並使用“dialog”作為前端:

TERM=$TERM DEBIAN_FRONTEND=dialog apt-get install -y python-catkin-tools


這在建立 Dockerfile 時對我有用:

如果您確實想輸入選單點,則以下解決方法將無濟於事。如果您對預設值感到滿意,在本例中,zone/city = "etc./etc.",解決方案如下,取自在docker下安裝時可以回答對話框問題嗎?:

  1. apt-get install -y python-catkin-tools改成

    DEBIAN_FRONTEND=noninteractive apt-get install -y python-catkin-tools
    

隱藏緊跟在後的命令的選單。

  1. 您也可以在 Dockerfile 安裝期間隱藏任何選單,然後將其放在開頭:

    ARG DEBIAN_FRONTEND=noninteractive
    
  2. 不要輸入此項,因為即使在圖像中,它也會保留為設定:

    ENV DEBIAN_FRONTEND=noninteractive
    

最好使用“1.”,因為您可能不想抑制出現的所有其他選單點。

相關內容