放入 bash 脚本时找不到 wget 命令
wget command not found while putting inside bash script
我写了以下 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=()
fi
for i in "${arr[@]}"
do
URL="https://"$i":8443"
echo "URL is $URL"
wget --no-check-certificate $URL/heapdump
done
第 16 行一直失败:wget:找不到命令
我找到了一些相关的帖子,但不知道如何解决这个问题。谢谢
如果您键入命令(不是内部命令或 shell 函数),bash 会在变量 PATH
中提到的目录中搜索此文件名称(wget
在你的例子中),它为用户 运行 脚本设置了可执行位。在你的情况下,没有找到合适的wget
。
由于您的 PATH 中不太可能有 wget
且未设置 x 位,最可能的原因是 PATH 缺少您的 wget 所在的目录。
您有两个选择:扩展 PATH,或者在脚本的 wget
行前明确加上正确的路径前缀,即
/here/is/my/wget --no-check-certificate $URL/heapdump
获取wget等可执行文件的路径请使用‘which’cmd:
which wget
输出:
/full/path/wget
我写了以下 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=()
fi
for i in "${arr[@]}"
do
URL="https://"$i":8443"
echo "URL is $URL"
wget --no-check-certificate $URL/heapdump
done
第 16 行一直失败:wget:找不到命令
我找到了一些相关的帖子,但不知道如何解决这个问题。谢谢
如果您键入命令(不是内部命令或 shell 函数),bash 会在变量 PATH
中提到的目录中搜索此文件名称(wget
在你的例子中),它为用户 运行 脚本设置了可执行位。在你的情况下,没有找到合适的wget
。
由于您的 PATH 中不太可能有 wget
且未设置 x 位,最可能的原因是 PATH 缺少您的 wget 所在的目录。
您有两个选择:扩展 PATH,或者在脚本的 wget
行前明确加上正确的路径前缀,即
/here/is/my/wget --no-check-certificate $URL/heapdump
获取wget等可执行文件的路径请使用‘which’cmd:
which wget
输出:
/full/path/wget