wget批处理linux文件

wget批处理linux文件

我正在尝试使用从制造商的网站下载图像wget。当我从 shell 运行命令时,它工作正常。但是当我从文件运行它时,我得到一个占位符文件。

这是命令:

wget --wait=2 --output-document=1000.jpg 'http://distributorcentral.com/resources/productimage.cfm?prod=8cb7afa6-73bf-4f9f-b251-38dc652779c9&size=large'

这是它在文件中的样子:

wget --wait=5 --output-document=1101.jpg 'http://distributorcentral.com/resources/productimage.cfm?prod=4d41b2ff-90a4-40c1-9159-2780cd642244&size=large'
wget --wait=5 --output-document=1102.jpg 'http://distributorcentral.com/resources/productimage.cfm?prod=5e88f32e-48f2-40db-bdbd-53624448392d&size=large'
wget --wait=5 --output-document=1103.jpg 'http://distributorcentral.com/resources/productimage.cfm?prod=59292a17-ae6f-49df-a028-0a9f71686f80&size=large'

我不明白为什么它不能作为批处理 shell 文件工作。

答案1

您知道需要在 Unix 上添加 x(执行)标志才能执行 shell 脚本吗? DOS 用户的另一个常见陷阱是,出于安全原因,通常没有“.”。在 PATH 环境中,因此您需要运行“./your-script”而不仅仅是“your-script”。

关于另一个答案中提到的she-bang。至少在 Linux 上,如果脚本中没有给出 she-bang,则 /bin/sh 是默认使用的 shell。始终向所有脚本添加一个仍然是一种很好的做法。

答案2

我在这里测试了一下,效果很好。你的顶部有一条她刘海线吗? #!/path/to/shell

答案3

获取输出

which bash

which wget

然后使用井号(#!)将返回的路径添加到脚本顶部的 bash 中。即如果 which bash 返回 /bin/bash 则使用。

#!/bin/bash

然后添加wget的返回路径。例子

/usr/bin/wget --wait=5 --output-document=1101.jpg 'http://distributorcentral.com/resources/productimage

最后确保您创建的脚本是可执行的chmod +x name-of-your-script

如果它不起作用,仍然尝试将 -x 添加到脚本中以获取一些调试信息。

#!/bin/bash -x

相关内容