WSL 看不到环境变量
WSL can't see environment variable
我目前正在寻求在 WSL 中运行的 MIPS 交叉编译器工具链,由 CLion 访问。
在那里,我在 WSL 方面遇到了一个奇怪的问题。我在.bashrc
中添加了以下内容:
STAGING_DIR="/home/max/source/staging_dir/toolchain-mipsel_24kc_gcc-5.4.0_musl-1.1.16"
export STAGING_DIR
此外,我有脚本test.sh
#!/bin/sh
echo "Staging dir is: " $STAGING_DIR
使用wsl
获取 shell 并执行脚本时,输出如下:
max@DESKTOP-ISH7UJQ:/mnt/c/Users/Maxi$ ./test.sh
Staging dir is: /home/max/source/staging_dir/toolchain-mipsel_24kc_gcc-5.4.0_musl-1.1.16
使用wsl <command>
在 WSL 中执行 bash 命令时,输出会有所不同。环境变量只是消失了。
C:UsersMaxi>wsl ./test.sh
Staging dir is:
似乎通过 wsl 执行时没有执行.bashrc
(我也试过.profile
(?
这是一个问题,因为当 CLion 调用 WSL 子系统以使用 CMake 生成我的C++项目时,编译器会抱怨此环境变量不存在。
当我手动获取 shell 并执行完全相同的 cmake 命令时,编译在没有警告的情况下工作,因为环境变量在那里。
CLion 内部:
/usr/bin/cmake --build /mnt/c/Users/Maxi/CLionProjects/linux_wsl_test/cmake-build-debug-wsl_omega --target all -- -j 2
Scanning dependencies of target linux_wsl_test
[ 50%] Building CXX object CMakeFiles/linux_wsl_test.dir/main.cpp.o
mipsel-openwrt-linux-g++: warning: environment variable 'STAGING_DIR' not defined
[100%] Linking CXX executable linux_wsl_test
mipsel-openwrt-linux-g++: warning: environment variable 'STAGING_DIR' not defined
mipsel-openwrt-linux-g++: warning: environment variable 'STAGING_DIR' not defined
[100%] Built target linux_wsl_test
在 WSL 外壳上:
max@DESKTOP-ISH7UJQ:~/build_dir$ /usr/bin/cmake --build /mnt/c/Users/Maxi/CLionProjects/linux_wsl_test/cmake-build-debug-wsl_omega --target all -- -j 2
[ 50%] Building CXX object CMakeFiles/linux_wsl_test.dir/main.cpp.o
[100%] Linking CXX executable linux_wsl_test
[100%] Built target linux_wsl_test
这是怎么回事?
~/.bashrc文件仅由交互式shell加载。当您以这种方式运行脚本时,它由非交互式 shell 处理。您可以使用-i
开关强制它是交互式的(尽管我不知道这是否适用于wsl
命令(。或者,在运行脚本之前将BASH_ENV=/home/max/.bashrc
放入环境中。
相关文章:
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 看不到文件'SDL2.lib'
- WSL 看不到环境变量
- 为什么我的 FreeRTOS 任务看不到类成员?
- Google Colab 看不到 .so 文件
- 派生类看不到基类成员
- 为什么我看不到字符串?
- CMake 看不到SDL2_PATH环境变量 (Windows)
- OpenMP 任务看不到共享变量的更改
- handleMessage看不到我的类和函数
- 为什么"gdb"看不到全局变量?
- 我需要创建一个函数在用户下打印"=",但由于变量是使用 main() 声明的,因此函数看不到参数
- 友元函数看不到私有成员变量
- C++ .cpp文件看不到来自 .h 的变量
- 将值分配给变量后获取垃圾值,看不到原因
- Visual Studio debug ghost cursor语言 - 程序进入调试,但看不到当前行或变量
- VS 2015 编译器看不到 C 变量
- 使用Visual Studio 2010时,在将调试器附加到程序时看不到托管变量名
- 我的程序执行了正确的#次循环,但是我看不到字符串变量
- CMake 看不到系统变量