我需要创建一个可以在mac上运行的bash脚本.它需要下载站点的ZIP文件并将其解压缩到特定位置.
curl -O)unzip filename.zip path/to/save)我需要这样做,以便人们可以双击桌面上的文本文件,它将自动在终端中运行.
如何制作它以便用户可以双击桌面上的图标并运行?该文件需要什么扩展名?
zed*_*xff 27
OSX使用与Linux相同的GNU sh/bash
#!/bin/sh
mkdir /tmp/some_tmp_dir && \
cd /tmp/some_tmp_dir && \
curl -sS http://foo.bar/filename.zip > file.zip && \
unzip file.zip && \
rm file.zip
Run Code Online (Sandbox Code Playgroud)
第一行#!/bin/sh是所谓的"shebang"线,是强制性的
rua*_*rio 17
BSD Tar可以打开zip文件并通过流解压缩.所以以下内容将起作用:
curl -SL http://example.org/file.zip | tar -xf - -C path/to/save
Run Code Online (Sandbox Code Playgroud)
如果您不想更改目录上下文,请使用以下脚本:
#!/bin/bash
unzip-from-link() {
local download_link=$1; shift || return 1
local temporary_dir
temporary_dir=$(mktemp -d) \
&& curl -LO "${download_link:-}" \
&& unzip -d "$temporary_dir" \*.zip \
&& rm -rf \*.zip \
&& mv "$temporary_dir"/* ${1:-"$HOME/Downloads"} \
&& rm -rf $temporary_dir
}
Run Code Online (Sandbox Code Playgroud)
用法:
# Either launch a new terminal and copy `git-remote-url` into the current shell process,
# or create a shell script and add it to the PATH to enable command invocation with bash.
# Place zip contents into '~/Downloads' folder (default)
unzip-from-link "http://example.com/file.zip"
# Specify target directory
unzip-from-link "http://example.com/file.zip" "/your/path/here"
Run Code Online (Sandbox Code Playgroud)
输出:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 17.8M 100 17.8M 0 0 22.6M 0 --:--:-- --:--:-- --:--:-- 22.6M
Archive: file.zip
inflating: /tmp/tmp.R5KFNvgYxr/binary
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30971 次 |
| 最近记录: |