Bash – Having multi lines in bash command substitution

bashshell-script

I have a very long bash command inside a command substitution like following:

$( comaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaand )

I want to know if there is a way to break this command into shorter lines for the sake of readability like following:

$( com 
   aaaaaaaaaaaaaa
   aaaaaaaaaaaaaa
   nd )

Best Answer

You can mask the newline with \.

$( com\
aaaaaaaaaaaaaa\
aaaaaaaaaaaaaa\
nd )

The \ tells the shell to ignore the newline.

Related Question