我正在尝试将source
与curl
结合使用。
但是,当我在我的机器上运行以下代码段(Mac OS 10.13.4)时,它会输出以下错误:read_os_name: command not found
。
read_os_name.sh
:
#!/bin/bash
declare -r UTILS_URL="https://raw.githubusercontent.com/nicholasadamou/bash-utils/master/utils.sh"
source <(curl -s "$UTILS_URL")
read_os_name #Should output "macos"
来自read_os_name()
的 utils.sh
:
read_os_name() {
local kernelName=""
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
kernelName="$(uname -s)"
if [ "$kernelName" == "Darwin" ]; then
printf "macos"
elif [ "$kernelName" == "Linux" ] && [ -e "/etc/os-release" ] || [ -e "/usr/lib/os-release" ]; then
local conf=""
if test -r /etc/os-release ; then
conf="/etc/os-release"
else
conf="/usr/lib/os-release"
fi
awk -F= '$1=="ID" { print $2 ;}' "$conf" | sed -e 's/^"//' -e 's/"$//'
fi
}