Skip to content

Instantly share code, notes, and snippets.

@Ragdata
Created February 22, 2021 13:45
Show Gist options
  • Save Ragdata/08cae4516f852b6a45ecac3e8b71cb27 to your computer and use it in GitHub Desktop.
Save Ragdata/08cae4516f852b6a45ecac3e8b71cb27 to your computer and use it in GitHub Desktop.
Execute a single file from a Github Repo remotely in a single command line
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | bash
@Ragdata
Copy link
Author

Ragdata commented Feb 22, 2021

-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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment