![대본](https://rvso.com/image/1628797/%EB%8C%80%EB%B3%B8.png)
대본
Windows Powershell에서 WSL Ubuntu 18.04에 일부 소프트웨어의 무인 설치를 구현하는 동안 명령 apt upgrade
은 다음 프롬프트를 반환합니다.
이 질문명령 을 실행하기 전에 WSL Ubuntu 18.04에서 환경 변수를 설정하여 이 메시지를 방지할 수 있다고 친절하게 설명합니다 apt upgrade
. 나는 이것이 실제로 작동하는지 확인했습니다. 그러나 Powershell에서 WSL Ubuntu 18.04에 대한 환경 변수를 설정하는 데 몇 가지 문제가 발생했습니다. 이러한 문제는 "시도" 섹션에 자세히 설명되어 있습니다.
질문
DEBIAN_FRONTEND=noninteractive
Powershell 스크립트에서 WSL Ubuntu 18.04의 환경 변수를 어떻게 설정합니까 ?
MWE
몇 가지 시도가 포함된 MWE가 아래에 포함되어 있습니다.
# First define path to the installed ubuntu1804.exe
$str1="/Users/"
$str2="/AppData/Local/Microsoft/WindowsApps/ubuntu1804"
$hdd_name=(Get-WmiObject Win32_OperatingSystem).SystemDrive
$username=$env:UserName
[String] $ubuntu1804_path=$hdd_name+$str1+$username+$str2
Write-Host "Done with setup now starting apt update ."
# perfrom apt update
$str1=" run 'yes | apt update'"
$command=$ubuntu1804_path+$str1
invoke-expression -Command $command
Write-Host "Performed Update, now setting env variable."
# set environment variable DEBIAN_FRONTEND=noninteractive
$str1=" run DEBIAN_FRONTEND=noninteractive"
$command=$ubuntu1804_path+$str1
invoke-expression -Command $command
Write-Host "Performed setting env variable, now performing upgrade."
# perfrom apt upgrade
$str1=" run 'yes | apt upgrade'"
$command=$ubuntu1804_path+$str1
invoke-expression -Command $command
Write-Host "Performed upgrade."
시도
처음에는 WSL에서 구문 분석하여 환경 변수를 설정하려고 했습니다 bash -c DEBIAN_FRONTEND=noninteractive
. 다음으로 나는 시도했다 wsl DEBIAN_FRONTEND=noninteractive
. 그런 다음 invoke-expression -Command
MWE에 설명된 대로 시도했습니다 . 이들 모두는 프롬프트에 멈춰 있습니다(처음 2개는 프롬프트를 표시하지 않지만 무기한 대기합니다(각각 2시간 이상 기다렸고 wsl 자체의 명령은 +- 30분만 소요됨을 확인했습니다)). Powershell의 프롬프트:
.
의심
3번의 시도에서 관찰된 내용은 다음 2가지 경우 중 하나를 의미한다고 생각합니다.
DEBIAN_FRONTEND=noninteractive
powershell에서 환경 변수를 올바르게 설정하지 않습니다 .- 또는 powershell이
DEBIAN_FRONTEND=noninteractive
일부 셸에서 환경 변수를 올바르게 설정했지만 다음 명령에 대해 환경 변수가 설정되지 않은 새 셸을 엽니다.
환경 변수가 올바르게 설정되었는지 확인하기 위해 running 을 시도했지만 wls에서 wsl printenv
실행하면 다른 목록이 반환됩니다 printenv
. DEBIAN_FRONTEND=noninteractive
wsl에서 환경 변수를 수동으로 설정하면 printenv
명령이 환경 변수를 올바르게 표시합니다. 그러나 WSL Ubuntu 18.04를 닫았다가 다시 열고 명령을 다시 실행하면 printenv
환경 변수가 사라졌습니다. 이 관찰은 의심스러운 옵션 2가 가능함을 의미합니다. 환경 변수 가 printenv
.printenv
답변1
DEBIAN_FRONTEND=noninteractive
내가 찾은 powershell 스크립트를 git에서 검색한 후예이는 다음 명령을 사용하여 powershell 스크립트에서 특정 명령에 대한 환경 변수를 지정할 수 있음을 보여줍니다.
# First define path to the installed ubuntu1804.exe
$str1="/Users/"
$str2="/AppData/Local/Microsoft/WindowsApps/ubuntu1804"
$hdd_name=(Get-WmiObject Win32_OperatingSystem).SystemDrive
$username=$env:UserName
[String] $ubuntu1804_path=$hdd_name+$str1+$username+$str2
# Run a command with an environment variable
$str1=" run DEBIAN_FRONTEND=noninteractive apt-get upgrade -y"
$command=$ubuntu1804_path+$str1
invoke-expression -Command $command
나는 이것이 실제로 사용자 상호 작용에 대한 프롬프트를 방지하여 XY 문제를 해결한다는 것을 확인했습니다. 아직 해당 셸의 환경 변수를 검사하여 이를 직접 확인할 수는 없지만추정하다이것은 실제로 (일시적으로) 환경 변수를 설정합니다 DEBIAN_FRONTEND=noninteractive
.