【问题标题】:wget command not found while putting inside bash script放入 bash 脚本时未找到 wget 命令
【发布时间】:2019-04-05 04:46:12
【问题描述】:

我编写了以下 bash 脚本:

 #!/bin/sh

echo "Number of command line arguments : $#"
if [ $# == 0 ]; then
   echo "Your command line contains no arguments"
   declare -a arr=("xx.xx.xx.xx" "yy.yy.yy.yy")
else
   declare -a arr=($1)
fi


for i in "${arr[@]}"
do
   URL="https://"$i":8443"
   echo "URL is $URL"
   wget --no-check-certificate $URL/heapdump
done

第 16 行一直失败:wget: command not found

我找到了一些相关的帖子,但不知道如何解决这个问题。谢谢。

【问题讨论】:

  • 在服务器中运行wget 时会输出什么?
  • 顺便说一句:sh 通常不是 bash。
  • 为了测试,将which wget 插入到您的脚本中。

标签: bash path wget


【解决方案1】:

如果您键入命令(不是内部命令或 shell 函数),bash 会在变量 PATH 中提到的目录中搜索此名称的文件(在您的情况下为 wget),该文件具有为运行脚本的用户设置的可执行位。就您而言,没有找到合适的wget

由于在没有设置 x 位的情况下,您的 PATH 中不太可能有 wget,因此最可能的原因是 PATH 缺少 wget 所在的目录。

您有两个选择:扩展 PATH,或在脚本中明确地为 wget 行加上正确的路径前缀,即

/here/is/my/wget --no-check-certificate $URL/heapdump

【讨论】:

    【解决方案2】:

    获取可执行文件的路径,如 wget,请使用 ‘which’ cmd:

    which wget
    

    输出:

    /full/path/wget
    

    【讨论】:

      猜你喜欢
      • 2013-10-18
      • 2020-10-25
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 2016-03-08
      • 1970-01-01
      相关资源
      最近更新 更多