Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use -Lo- with curl when piping to bash?

Tags:

bash

curl

In the janus project, they use curl to download and pipe a bootstrap script into bash. https://github.com/carlhuda/janus

It looks like this:

$ curl -Lo- https://bit.ly/janus-bootstrap | bash

Why would one want to use the args -Lo-?

-o is supposed to be for output, but wouldn't that happen anyway (i.e. to stdout)?

like image 295
adzdavies Avatar asked Oct 02 '15 01:10

adzdavies


People also ask

Can you use curl in bash script?

If you've ever sat in front of a terminal, typed 'curl', pasted the URL of something you want to download, and hit enter, cool! You're going to be killing it with curl in bash scripts in no time. Here you will learn how to use curl in bash scripts and important tips and tricks for automation.

What is curl in shell script?

curl is a command-line tool to transfer data to or from a server, using any of the supported protocols (HTTP, FTP, IMAP, POP3, SCP, SFTP, SMTP, TFTP, TELNET, LDAP, or FILE). curl is powered by Libcurl. This tool is preferred for automation since it is designed to work without user interaction.

What does piping do in bash?

A pipe in Bash takes the standard output of one process and passes it as standard input into another process. Bash scripts support positional arguments that can be passed in at the command line.

How do I run bash curl?

In the bin folder, you will find the curl.exe file and libcurl library. You can add the bin folder to your PATH environment variable so you can execute Curl commands from anywhere. The Curl/Bash code was automatically generated for the Curl For Windows example.


2 Answers

It's all in the man pages:

-L in case the page has moved (3xx response) curl will redirect the request to the new address

-o output to a file instead of stdout (usually the screen). In your case the o flag is redundant since the output is piped to bash (for execution) - not to a file.

like image 128
Nir Alfasi Avatar answered Oct 09 '22 03:10

Nir Alfasi


The -o is redundant, they produce the exact same output:

$ curl --silent example.com | sha256sum
3587cb776ce0e4e8237f215800b7dffba0f25865cb84550e87ea8bbac838c423 *-

$ curl --silent --output - example.com | sha256sum
3587cb776ce0e4e8237f215800b7dffba0f25865cb84550e87ea8bbac838c423 *-

They have used that syntax since that line was first introduced in 2011. You might ask Wael Nasreddine (@kalbasit on GitHub) why he did it. He is still active on that repo.

like image 4
5 revs Avatar answered Oct 09 '22 03:10

5 revs