我目前正在使用 linux 并想撰寫一個 bash 腳本,它按照我想要的方式設定一臺新機器。
為了做到這一點,我想在上面安裝不同的東西等等。
我在這里試圖實作的是在 bash 腳本的頂部設定一個設定,這將使 apt 接受在腳本執行期間提出的所有 [y/n] 問題
我想自動接受的問題示例:
After this operation, 1092 kB of additional disk space will be used. Do you want to continue? [Y/n]
我剛剛開始創建檔案,所以這是我目前所擁有的:
#!/bin/bash
# Constants
# Set apt to accept all [y/n] questions
>> some setting here <<
# Update and upgrade apt
apt update;
apt full-upgrade;
# Install terminator
apt install terminator
uj5u.com熱心網友回復:
apt旨在以互動方式使用。如果您想自動化操作,請查看apt-get,特別是它的-y選項:
-y, --yes, --assume-yes
自動是對提示;假設“是”作為對所有提示的回答并以非互動方式運行。如果發生不良情況,例如更改保留的軟體包、嘗試安裝未經身份驗證的軟體包或洗掉必要的軟體包,則 apt-get 將中止。配置項:APT::Get::Assume-Yes。
另請參閱man apt-get更多選項。
uj5u.com熱心網友回復:
與apt:
apt -o Apt::Get::Assume-Yes=true install <package>
見:man apt和man apt.conf
uj5u.com熱心網友回復:
如果你確實想像你說的那樣在檔案頂部設定一次然后忘記它,你可以使用APT_CONFIG環境變數。見apt.conf。
echo "APT::Get::Assume-Yes=yes" > /tmp/_tmp_apt.conf
export APT_CONFIG=/tmp/_tmp_apt.conf
apt-get update
apt-get install terminator
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/341793.html
