Bash源命令不能与`curl`一起使用

时间:2018-05-31 22:40:23

标签: bash shell url

我正在尝试将sourcecurl结合使用。

但是,当我在我的机器上运行以下代码段(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

}

0 个答案:

没有答案