What do the '&&
', '\
' and '-
' mean at the end of bash commands?
In particular, I came across the following combination of lines that are supposed to add public keys to Ubuntu's aptitude package manager, what are those characters used here for?
gpg --keyserver keyserver.ubuntu.com --recv 26C2E075 && \ gpg --export --armor 26C2E075 | sudo apt-key add - && \ sudo apt-get update
Best Answer
"&&" is used to chain commands together, such that the next command is run if and only if the preceding command exited without errors (or, more accurately, exits with a return code of 0).
"\" by itself at the end of a line is a means of concatenating lines together. So the following two lines:
are processed exactly the same as if the line was written as the single line:
"-" is a command line argument with no specific bash function. Exactly how it is handled is dependent on the command being run (in this case apt-key). Depending on context, it's typically used to indicate either "read data from stdin rather than from a file", or "process the remainder of the line as data rather than as command line arguments".