首页 > shell中有没有类型__name__ __main__ 的功能?

shell中有没有类型__name__ __main__ 的功能?

shell脚本怎么检测自已是被导入还是被运行?


bash可以这样:

#!/bin/bash

if [ "$0" = "$BASH_SOURCE" ]; then
    echo "directly run"
else
    echo "sourced from another shell script"
fi

你可以自己运行尝试看看输出结果

【热门文章】
【热门文章】