gpt4 book ai didi

Bash 脚本 "Command Not Found Error"

转载 作者:行者123 更新时间:2023-11-29 09:25:10 26 4
gpt4 key购买 nike

我正在编写一个 bash 脚本来下载 imgur 相册以用于目的或学习 bash。到目前为止我已经写了这么多但是当我运行它时我得到这个输出:

Enter the URL of the imgur album you would like to download: imgur.com
./imgur_dl.sh: line 25: Validating: command not found
./imgur_dl.sh: line 26: Getting: command not found
./imgur_dl.sh: line 30: imgur.com: command not found

到目前为止,这是我的代码。

#!/bin/bash

url=""
id=""

get_id(){
echo "Getting Album ID..."
local url=$1
echo $url
echo "Successflly got Album ID..."
return
}

validate_input(){
echo "Validating Input..."
local id=$1
echo $id
echo "Input Validated Successfully..."
return
}

get_input(){
read -p "Enter the URL of the imgur album you would like to download: " url
echo $url
$(validate_input url)
$(get_id url)
return
}

$(get_input)

我做错了什么或者我没有得到什么?我在 macOS 上工作,它完全有帮助。

最佳答案

只需直接调用函数,例如:

valide_input $url

等等。

    #!/bin/bash

url=""
id=""

get_id ()
{
echo "Getting Album ID..."
local url=$1
echo $url
echo "Successflly got Album ID..."
return
}

validate_input ()
{
echo "Validating Input..."
local id=$1
echo $id
echo "Input Validated Successfully..."
return
}

get_input ()
{
read -p "Enter the URL of the imgur album you would like to d ownload: " url
echo $url
validate_input $url
get_id $url
return
}

get_input

此外,正如其他人所建议的,您可以通过将 $Url 放在双引号内来改善这一点,例如

validate_input "$url"

因此它处理其他无效的 url。

关于Bash 脚本 "Command Not Found Error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46695443/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com