Bash – What does this command with a backslash at the end do

bashcurlshell-script

curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.10.0/docker-machine-driver-kvm-ubuntu14.04 > /usr/local/bin/docker-machine-driver-kvm \

It downloads a file called docker-machine-driver-kvm-ubuntu14.04, and then? sends it to the directory /usr/local/bin/docker-machine-driver-kvm?

Also, what about the \ at the end?

Best Answer

That looks like an error, if the line is to be interpreted by itself.

A backslash escapes the next character from being interpreted by the shell. If the next character is a newline, then the newline will not be interpreted as the end of the command by the shell. It effectively allows the a command to span multiple lines.

It is most commonly used in situations like these (i.e. to make it easier to read a long command):

rsync --archive \
      --verbose \
      user@source:/dir/ \
      user@target:/dir/

Notice that the last line does not end with \ since it is not continued on the next line. Also note that nothing (not even a comment or a single space) may follow the \ on the lines that are broken up in this way.

Apart from that, yes, the command downloads a file and saves it to a file on disk. Another way of doing the same thing, without a redirection, would be to us Curl's -o option:

curl -L \
    -o /usr/local/bin/docker-machine-driver-kvm \
    https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.10.0/docker-machine-driver-kvm-ubuntu14.04 \

(followed by whatever is on the next line in your script)

Related Question