【发布时间】:2019-04-02 18:24:00
【问题描述】:
我有一个可执行文件,它应该从一个链接下载一个 zip 文件并解压缩它。
#!/bin/bash
echo “Downloading project resources from Storage...”
if curl -O -J -L https://mylink.com; then
unzip filename.zip
else
echo "Something went wrong"
fi;
echo "Done!"
但是,不知何故,我的脚本在解压缩文件之前不会等待curl 完成下载。我做错了什么?
输出:
MacBook-Pro:~ ej$ /Users/ej/Desktop/untitled\ folder\ 2/Setup ; exit;
“Downloading project resources from Storage...”
unzip: cannot find or open file.zip, file.zip.zip or file.zip.ZIP.
Done!
logout
Saving session... % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
最后,在运行可执行文件的文件夹中没有下载或解压缩文件。
编辑 2:
ls -l 在终端运行 curl 命令后输出如下:
-rwxr--r--@ 1 ej staff 390 2 Apr 21:42 Setup
-rw-r--r-- 1 ej staff 86368932 2 Apr 22:19 file.zip?alt=media
which bash 输出以下内容:
/bin/bash
附: MacBook 上是否预装了 curl?
【问题讨论】:
-
你能粘贴你得到的确切输出吗?是什么让你觉得下载没有完成?
-
@akskap 我在上面编辑了我的问题。
-
看起来您尝试使用
unzip访问的文件名与下载的文件名不同。在终端中运行 curl 命令后,您可以粘贴ls -l的输出吗?也请告诉which bash的输出 -
@akskap,再次更新
-
感谢您提供详细信息 - 在下面发布了脚本的修订版
标签: bash shell unix command-line