Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write a BASH script to download and unzip file on a Mac?

Tags:

bash

macos

unzip

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.

  1. Download the ZIP file (curl -O)
  2. Unzip the files to a specific location (unzip filename.zip path/to/save)
  3. 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?

like image 615
alecwhardy Avatar asked Dec 19 '11 04:12

alecwhardy


People also ask

How do I unzip a zip file in shell script?

To extract the files from a ZIP file, use the unzip command, and provide the name of the ZIP file. Note that you do need to provide the “. zip” extension. As the files are extracted they are listed to the terminal window.


1 Answers

OSX uses the same GNU sh/bash as Linux

#!/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 

the first line #!/bin/sh is so called "shebang" line and is mandatory

like image 190
zed_0xff Avatar answered Sep 21 '22 13:09

zed_0xff