bluetoothlover_doc icon indicating copy to clipboard operation
bluetoothlover_doc copied to clipboard

【shell】判断当前执行shell脚本的环境

Open chenyingchun0312 opened this issue 1 year ago • 0 comments

以下是一个可以用于判断当前系统环境的shell脚本:

#!/bin/bash

if [[ "$(uname)" == "Linux" ]]; then
    echo "当前系统环境为Linux"
elif [[ "$(uname)" == "CYGWIN"* ]]; then
    echo "当前系统环境为Cygwin"
elif [[ "$(uname)" == "MINGW"* ]]; then
    echo "当前系统环境为Mingw"
else
    echo "未知系统环境"
fi

该脚本使用了$(uname)命令来获取当前系统的信息,通过判断该信息中的关键词来确定当前系统环境是否为Linux、Cygwin或Mingw。如果无法确定当前系统环境,则会输出“未知系统环境”。

image

chenyingchun0312 avatar Apr 23 '23 14:04 chenyingchun0312