在wsl中判断wsl的版本是wsl1还是wsl2
WSL
Issues found on WSL
项目地址:https://gitcode.com/gh_mirrors/ws/WSL
免费下载资源
·
判断wsl的版本
代码逻辑
通过判断 cat /proc/version
,是否包含wsl
等字符来判断wsl的版本。
代码
#!/bin/bash
# Get the content of /proc/version
proc_version=$(cat /proc/version)
# Check if we are running within WSL
if echo $proc_version | grep -qi 'Microsoft'; then
# Check if it's WSL1 or WSL2
if echo $proc_version | grep -qi 'WSL2'; then
version="WSL2"
else
version="WSL1"
fi
else
version="Linux"
echo "Not running within WSL."
exit 1
fi
# Set host_ip based on WSL version
if [ "$version" == "WSL1" ]; then
host_ip="127.0.0.1"
#echo "export host_ip=127.0.0.1" >> ~/.bashrc
#echo "export DISPLAY=$host_ip:0.0" >> ~/.bashrc
else
host_ip=$(grep nameserver /etc/resolv.conf | cut -f 2 -d " ")
#echo 'host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ")' >> ~/.bashrc #对应于WSL2
echo "export DISPLAY=$host_ip:0.0" >> ~/.bashrc
fi
echo "WSL version: $version"
echo "host_ip: $host_ip"
GitHub 加速计划 / ws / WSL
17.09 K
797
下载
Issues found on WSL
最近提交(Master分支:1 个月前 )
86fa5afa
2 个月前
e899d0b7
2 个月前
更多推荐
已为社区贡献2条内容
所有评论(0)