如何编写 BASH 脚本来在 Mac 上下载并解压缩文件?
我需要创建一个可以在 Mac 上运行的 bash 脚本。它需要下载站点的 ZIP 文件并将其解压缩到特定位置。
- 下载 ZIP 文件 (
curl -O
) - 将文件解压到特定位置 (
unzip filename.zip path/to/save
) - .zip 文件
删除我需要制作的 这样人们就可以双击桌面上的文本文件,它将自动在终端中运行。
如何使用户双击桌面上的图标即可运行?该文件需要什么扩展名?
I need to create a bash script that will work on a mac. It needs to download a ZIP file of a site and unzip it to a specific location.
- Download the ZIP file (
curl -O
) - Unzip the files to a specific location (
unzip filename.zip path/to/save
) - Delete the .zip file
I need to make it so people can double-click the text file on their desktop and it will automatically run in terminal.
How do I make it so that the user can double click the icon on the desktop and it will run? What extension does the file need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
OSX 使用与 Linux 相同的 GNU sh/bash
第一行
#!/bin/sh
被称为“shebang”行,并且是强制性的OSX uses the same GNU sh/bash as Linux
the first line
#!/bin/sh
is so called "shebang" line and is mandatoryBSD Tar 可以打开 zip 文件并通过流解压缩。 -L 或 --location 标志用于遵循重定向。因此,以下内容将起作用:
BSD Tar can open a zip file and decompress through a stream.The -L or --location flag is to follow redirects. So the following will work:
如果您不想更改目录上下文,请使用以下脚本:
用法:
输出:
If you do not want change directory context, use the following script:
Usage:
Output: