I'll try again, this time doing it one step at a time....

That worked!

So, it's important to note that you do the steps one by one. I'll remember that.

It's not strictly necessary to post them 1 line at a time. The problem occurs when you are not already in an sudo session. When the system requests your sudo password for the first time it runs the first command, but subsequently forgets the remaining commands. If you happen to already be in a sudo session each of the commands will run up to the last one, then hitting the enter key will cause the last command to run.

If you initiate an sudo session before pasting the block of commands, I do this by typing something like "sudo erkgthaeiugtheriu" in other words a non existant command, entering my password when propted (the system then throws an error along the lines of can't find command, then waits for valid commands), then I paste in the block of commands. They then all run fine.