在我在cd
文件夹中编辑后的脚本中,我检查direnv
系统中是否有可用的命令以及是否.envrc
已经创建了文件。如果是这样,我正在生成一个 python 虚拟环境:
direnv allow
eval "$(direnv export bash)"
由于某些原因,VIRTUAL_ENV
变量值前面有一个美元符号,之后我无法按我的意愿管理它。这是执行此操作的完整功能。
python_venv_binary() {
if [ `command -v direnv &>/dev/null;` ] && [ -f ".envrc" ]; then
direnv allow
eval "$(direnv export bash)"
echo $VIRTUAL_ENV
# prints $/home/whatever/whatever/whatever/.direnv/python-3.8.5
$VIRTUAL_ENV/bin/python
fi
}
python_venv_binary
# $/home/whatever/whatever/whatever/.direnv/python-3.8.5/bin/python: not found
我将脚本作为sh script.sh
. 奇怪的是,手动运行相同的命令行为正确。
这set -x
是输出(我已经发布了我认为与案例相关的内容)。奇怪的是,exports 的$
前面都是一个,这似乎表明了这个问题。
+ command -v direnv
+ [ /usr/bin/direnv ]
+ [ -f .envrc ]
+ direnv allow
+ direnv export bash
direnv: loading ~/Development/kitty/.envrc
direnv: export +VIRTUAL_ENV ~PATH
+ eval export DIRENV_DIR=$'-/home/bernardo/Development/kitty';export VIRTUAL_ENV=$'/home/bernardo/Development/kitty/.direnv/python-3.8.5';export DIRENV_DIFF=$'eJzs1k1vmzAYB_Dv4nMSorgJBGkHHNIApSEJL-24IEKcQDCGGIe8VPnuU9utndLtsmmHqb7hx_7_hCxLz_MEKqA-gZnmGUAFUloWWFpiRmO2KqUOKZOYSMuMqlc7L6V9zaS3E1IRs03JoxRjEiUku04IS1jCEpawhPU31nuw_gi9Lt83Xj5el2-1TVzg-ufc90JN4-r5FLi0AH3uibq5GE-DSDcXQAXtq1_ScYNJWRWYcinPOD-B1o_Ag-aNjLELVICtY_dc3zqprs3RHsHBY3GeywmfnynrJq6seEhfH-6O_u39Li7PjUy73mNbt4eRtaU7n4dbt0u0Xr6zGz9wNsiCVh_KGsSEL9uDr2zIpk6_uMNuwRjazuKmmSG0bxsZpMpDOewVthHo0RFHxGn2_skdBFm-4VZch0ruhKvZJHPze5NAYxRM0GrUd9e8H_IULRNrelMfUBbCYDAZIMPlrDYrhzhrOegpwxRuIW66tqbpUXQ63HiO-QW0fjNEfLgpqbPKGKaNVJ14WtI27Cid_q8eyv_wHIUlLGEJS1ifw_r340cLBObC8zU7Gk-DP22n4HL5FgAA___9FMRg';export DIRENV_WATCHES=$'eJx0zsFOhDAQBuB36XmzQ7ctQznr0cS78TBDfwKxUFMqaozv7n0TX-DL9_JjnqUtZjS0lA2kqLvUVOgBJ3J537A3eltb-6Yr9rNO5mKeSmrrBjPavvPBBu-Hi3n8Wo92mLHVD_xe_lOvuUyS6VikgtJasZ8kOZdPGiSkMIl3HCVGBdC5Sft5ZthBbcJN4swBiZ3V6G6BHStrsIpOlOf7V289h3j3ev0LAAD__yw4TOI='
+ export DIRENV_DIR=$-/home/bernardo/Development/kitty
+ export VIRTUAL_ENV=$/home/bernardo/Development/kitty/.direnv/python-3.8.5