找出bash脚本在主机(或在主机映像中)在哪个环境中运行的最佳方法是什么?
我的bash脚本:
#!/bin/bash
function PKG_ABSENT { return `which "$1" 2>/dev/null | grep -cm1 "$1"`; }
if ! PKG_ABSENT "docker"; then
# Docker package is installed
echo "running in the host machine"
else
# Docker package is not installed
echo "running in a Docker image"
fi
有什么想法吗?