Explaining Different Approaches to Line Continuations in Bash, Python and Powershell

The aim of this page📝 is to review the concept of line discontinuation in bash, python and powershell.

The escape provides a means of writing a multi-line command.

  • By default — each separate line constitutes a different command in Bash
  • Escape character — - within command at the end of line escapes the newline, provided you put it into double quotes (quoting is a different story altogether)
  • What matters here is escape character outside of strings, at the end of script lines
  • If a script line ends with a pipe then an escape is unnecessary as pipe is a "natural line continuator"
  • According Advanced Bash-Scripting Guide, it is a good programming practice to always escape the EOL of code continuing into the newline
  • I have not been doing this in python, nor in powershell
  • Quite the opposite!
  • In Powershell, my approach has been defined by Get-PowerShellBlog > Bye Bye Backtick: Natural Line Continuations in PowerShell and I would never use a (backtick, which is an escape char) as it's just invisible
  • In Python, my approach has been, naturally, defined by https://pep8.org/#maximum-line-length which clearly prefers implied line continuation inside parentheses, brackets and braces
  • Let’s stay in bash and conclude that the following are synonymous and the third one is recommended if you want to break code into multiple lines

LINKS

--

--

Infrastructure Support Engineer/Technical Writer (snowplow.io) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (snowplow.io) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com