How to execute a Bash script from Github?
Load the file (make sure you use the raw file, otherwise you load the HTML page!) with wget
using its exact URL and then pipe the output to bash
:
Here's an example with clarifications:
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | bash
From the manpage for the wget
command:
-O file --output-document=file The documents will not be written to the appropriate files, but all will be concatenated together and written to file. If - is used as file, documents will be printed to standard output, disabling link conversion. (Use ./- to print to a file literally named -.) Use of -O is not intended to mean simply "use the name file instead of the one in the URL;" rather, it is analogous to shell redirection: wget -O file http://foo is intended to work like wget -O - http://foo > file; file will be truncated immediately, and all downloaded content will be written there.
So outputting to -
will actually write the files content to STDOUT and then you simply pipe it to bash
or whatever shell you prefer. If you script needs sudo
rights you need to do sudo bash
at the end so the line becomes:
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | sudo bash
If your script has user entries like read user_input
try this:
bash <(curl -s https://raw.githubusercontent.com/username/project/branch/path/file.sh)
The -s
parameter don't show download progress.