0

I'm writing a doc about installation of my soft and I have to write things like

Please do the following:

  sudo apt-get update
  sudo apt-get install python-dev cython portaudio19-dev

The idea is: people are going to copy/paste these two lines into their bash and then hit ENTER.

What's a clean way to write multiline commands, such that it will be copy/pasted into bash?

sudo apt-get update
sudo apt-get install python-dev cython portaudio19-dev

or

sudo apt-get update ;
sudo apt-get install python-dev cython portaudio19-dev

or

sudo apt-get update &&
sudo apt-get install python-dev cython portaudio19-dev

or something else?

Note: of course, I could provide a .sh script, but here the question is more about: what's a clean way to write a multiline command, such that it'll work when copy/pasting it.

2

The first one isn't going to work in general if at all.

Option two is ; but recognise that it says run command one after the other irrespective of whether the first ran successfully. So if first command failed the second one would run anyway.

Option three is && which means in your example, run second command only if first command was successful.

| improve this answer | |
1

You don't have to do anything special, the CLI sees the invisible carriage return and then goes to the next line. Just highlight, copy, and paste!

| improve this answer | |
1

Best is 3rd I think. With the first and second, all but the last command will be executed. Then you'll have to hit enter again.

| improve this answer | |
1

I personally use the double-ampersand (&&) and keep everything on one single line if I'm typing. If I'm copying and pasting into a PuTTY window, then I can just copy and paste, and all the commands get executed, as if I typed them in and pressed Enter manually after each line.

The additional great thing about the && is that the command will stop if there is an error, and won't continue. This lets me see what part was wrong, and correct it (typo? Wrong working directory? Not root [my company doesn't use sudo -.-]?).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.