首页 > 解决方案 > Bash 源命令不适用于“curl”

问题描述

我正在尝试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

}

标签: bashshellurl

解决方案


推荐阅读