我有一個.profile在運行之前在容器構建期間復制到 /home/vscode 的內容common-debian.sh
common-delian.sh這很重要,因為如果檔案已經存在,在容器映像構建期間將跳過創建默認 .profile
在該組態檔中,我有許多 bash 函式和一些匯出的變數。
其中一個變數依賴于執行宣告的函式之一,在我的 shell 中,我可以看到正確的變數和值已設定。
在 vscode 中打開新的集成終端時會出現此問題。“新終端”命令
但是,我的任何函式都不能在 shell 中執行。通過確認typeset -F
我可以運行source ~/.profile,然后這些功能在 shell 中可用。
有什么地方我可以打開日志來確定這里發生了什么?
有關安裝的詳細資訊
vscode 主機安裝的是 Mac M1
VERSION='0.202.6'
CONTENTS_URL='https://github.com/microsoft/vscode-dev-containers/tree/main/containers/debian/history/0.202.6.md'
DEFINITION_ID='debian'
VARIANT='bullseye'
GIT_REPOSITORY='https://github.com/microsoft/vscode-dev-containers/'
GIT_REPOSITORY_RELEASE='v0.224.0'
BUILD_TIMESTAMP='Fri, 25 Feb 2022 10:48:36 GMT'
示例函式宣告
kconfig() {
ls $HOME/.kube/configs/* | tr '\n' ':'
}
declare -f kconfig
使用示例變數
export KUBECONFIG="$(kconfig)"
我可以在采購 .profile 之前確認,此變數已設定且有效,并且應該僅來自 .profile 宣告。
供參考的主檔案夾
vscode ? /workspace (master ?) $ ls -al ~
total 76
drwxr-xr-x 1 vscode vscode 4096 Apr 27 18:59 .
drwxr-xr-x 1 root root 4096 Feb 25 10:55 ..
drwxr-xr-x 1 501 dialout 160 Mar 8 22:31 .aws
-rw-r--r-- 1 vscode vscode 220 Aug 4 2021 .bash_logout
-rw-r--r-- 1 vscode vscode 4665 Feb 25 10:55 .bashrc
drwxr-xr-x 3 vscode vscode 4096 Apr 27 18:59 .cache
drwxr-xr-x 1 501 dialout 192 Apr 25 21:41 .config
drwxr-xr-x 1 501 dialout 160 Apr 27 14:20 .creds
-rw-r--r-- 1 vscode vscode 500 Apr 27 18:59 .gitconfig
drwx------ 2 vscode vscode 4096 Apr 27 18:59 .gnupg
drwxr-xr-x 1 501 dialout 160 Mar 9 21:59 .kube
drwxr-xr-x 12 vscode vscode 4096 Feb 25 10:55 .oh-my-zsh
-rw-r--r-- 1 vscode vscode 2381 Apr 27 19:19 .profile
drwxr-xr-x 1 vscode root 4096 Apr 27 18:59 .vscode-server
drwxr-xr-x 3 vscode root 4096 Apr 27 18:26 .vscode-server-insiders
-rw-r--r-- 1 vscode vscode 3897 Feb 25 10:55 .zshrc
編輯如下:
現在我正在復制這個檔案,因為~/.bash_profile
仍然有一個 .profile,common-debian.sh如果在構建容器映像時檔案不存在,vscode 會創建這個檔案。
vscode ? /workspace (master ?) $ ls -al ~
total 80
drwxr-xr-x 1 vscode vscode 4096 Apr 27 20:08 .
drwxr-xr-x 1 root root 4096 Feb 25 10:55 ..
drwxr-xr-x 1 501 dialout 160 Mar 8 22:31 .aws
-rw-r--r-- 1 vscode vscode 220 Aug 4 2021 .bash_logout
-rw-r--r-- 1 vscode vscode 2671 Apr 27 19:57 .bash_profile
-rw-r--r-- 1 vscode vscode 4665 Feb 25 10:55 .bashrc
drwxr-xr-x 3 vscode vscode 4096 Apr 27 20:08 .cache
drwxr-xr-x 1 501 dialout 192 Apr 25 21:41 .config
drwxr-xr-x 1 501 dialout 160 Apr 27 14:20 .creds
-rw-r--r-- 1 vscode vscode 500 Apr 27 20:08 .gitconfig
drwx------ 2 vscode vscode 4096 Apr 27 20:08 .gnupg
drwxr-xr-x 1 501 dialout 160 Mar 9 21:59 .kube
drwxr-xr-x 12 vscode vscode 4096 Feb 25 10:55 .oh-my-zsh
-rw-r--r-- 1 vscode vscode 807 Aug 4 2021 .profile
drwxr-xr-x 1 vscode root 4096 Apr 27 20:08 .vscode-server
drwxr-xr-x 3 vscode root 4096 Apr 27 20:07 .vscode-server-insiders
-rw-r--r-- 1 vscode vscode 3897 Feb 25 10:55 .zshrc
還將以下內容添加到 /etc/profile.d/
# This file is intended to be copied into /etc/profile.d
project_profile="$HOME/.bash_profile"
if [ -r $project_profile ]; then
source $project_profile
else
echo "File not found or not readable: $project_profile"
fi
其中沒有一個對生成的新 shell 產生影響,也許忽略 vscode
docker exec -it {container} /bin/bash仍然有相同的結果。
我還嘗試使用空 shell 組態檔創建一個空終端組態檔,從該終端視窗啟動 vscode。認為可能繼承的 env 會導致問題。
同時設定以下用戶設定
"terminal.integrated.inheritEnv": false,
uj5u.com熱心網友回復:
從 bash 的手冊頁(在 INVOCATION 部分中):
當 bash 以非互動方式啟動時,例如運行一個 shell 腳本,它會在環境中查找變數 BASH_ENV,如果它出現,則擴展其值,并將擴展值用作要讀取和執行的檔案名. Bash 的行為就像執行了以下命令:
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi但 PATH 變數的值不用于搜索檔案名。
在您的用例中,即 shell 腳本,沒有讀取啟動檔案。但是您可以通過將 BASH_ENV 的值設定為要在啟動時讀取的檔案來更改它。或者,您的腳本可以在運行時獲取您喜歡的任何內容,例如source .profile.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/466433.html
標籤:重击 视觉工作室代码 vscode-远程 vscode 开发容器
上一篇:對于Windows本機應用程式,WSLPOSIX路徑如何轉換為UNC?
下一篇:如何啟用特定的VScode通知?
