无法运行使用“wget -o filename.sh <URL>”下载的脚本

Pas*_*are 5 command-line wget

我跑了这个:

wget -o ready-for.sh "https://training.linuxfoundation.org/cm/prep/ready-for.sh"
chmod a+x ./ready-for.sh
./ready-for.sh LFS265
Run Code Online (Sandbox Code Playgroud)

并得到错误:

ready-for.sh line-1 command not found
Run Code Online (Sandbox Code Playgroud)

hee*_*ayl 14

您使用了错误的 选项wget

要保存文档/文件,您需要-O(大写 o)。要保存日志,即 STDERR 上显示的任何内容,您需要-o.

当您使用 时-o,您已将日志另存为,ready-for.sh并且大概该文件不包含 可理解的任何内容bash,因此出现错误。

简而言之,请执行以下操作:

wget -O ready-for.sh "https://training.linuxfoundation.org/cm/prep/ready-for.sh"
Run Code Online (Sandbox Code Playgroud)

然后您应该能够以ready-for.sh通常的方式执行脚本。

也不要忘记检查man wget.

  • 在这种情况下,`-O ready-for.sh` 可以省略,因为服务器上的文件名已经相同,因此没有必要再次指定它。 (4认同)