How do I paste multi-line bash codes into terminal and run it all at once?

Nathan picture Nathan · Jul 15, 2011 · Viewed 97.9k times · Source

I need to paste a multi-line bash code into terminal, but whenever I do, each line gets run as a separate command as soon as it gets pasted.

Answer

opsguy picture opsguy · Jul 15, 2011

Try putting \ at the end of each line before copying it.

Example:

echo "Hello world" && \
script_b.sh

echo $?

The exit code ($?) is now the full sequence of commands, and not just the last command.