bash - 放入 bash 脚本时未找到 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=($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
我找到了一些相关的帖子,但不知道如何解决这个问题。谢谢。
解决方案
如果您键入命令(不是内部命令或 shell 函数),bash 会在变量中提到的目录中搜索PATH
此名称的文件(wget
在您的情况下),该文件为运行的用户设置了可执行位脚本。在你的情况下,没有找到合适wget
的。
由于wget
您的 PATH 中不太可能没有 x 位设置,因此最可能的原因是 PATH 缺少 wget 所在的目录。
您有两个选择:扩展 PATH,或wget
在脚本中明确地为该行添加正确路径的前缀,即
/here/is/my/wget --no-check-certificate $URL/heapdump
推荐阅读
- php - 无法显示php文件的结果,帮帮我
- java - CSAwesome 第 6.3 章
- php - PHP preg_match 函数未按预期工作
- javascript - 如何在图像上添加导航栏
- python - 如何使用 xlsxwriter 在 Excel 中创建直方图?
- hyperledger-fabric - 运行 Hyperledger Fabric 基本网络时出现问题:验证 ReadSet 时出错
- javascript - Jest mocks - 如何在测试之间恢复原始功能
- .htaccess - 使用 .htaccess 应用多个规则
- c# - WPF 依赖属性已更改但未在绑定中生效
- python - 如何在一个目录中添加(合并)多个图像