Bash 脚本 "Command Not Found Error"

标签 bash

我正在编写一个 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/

相关文章:

MySQL命令行执行

gitattributes - 如何识别没有扩展名的 bash 脚本文件

linux - 我如何使用 curl 命令从 bash 脚本获取 HTTP 响应?

linux - Linux 中过程镜像的绝对和相对路径

linux - 无需创建中间进程即可切换用户

bash - 您可以更新 github 项目的 README.md 而无需先手动 fork 吗?

linux - 如何使用 bash 脚本计算单词中出现次数最多的 3 个字母序列

bash - 挂载卷中的Docker用户权限

regex - Bash:遍历不匹配扩展名的文件

linux - 在 bash 中捕获信号但不完成当前正在运行的命令