allsap
allsap

Reputation: 333

How to split argument to `bash -c` on multiple lines?

I have a very long command I need to pass to bash via -c, e.g. '/bin/bash' '-c' 'my long command' (it's called as an array by something like python's subprocess (but not python)).

Is there anyway I can split 'my long command' onto multiple lines? I've tried 'my\ long\ command' but it didn't work.

Upvotes: 4

Views: 4933

Answers (1)

Nahuel Fouilleul
Nahuel Fouilleul

Reputation: 19315

if the resulting string argument must be one-line, it can be formed concatenating quoted strings and use backslash newline, to format them on multiple lines

echo 'a very very ...'\
'long string'

note that trailing and leading spaces outside quoted string are significant and are used to split arguments.

The following commands also works

bash -c 'echo \
hello'

because the bash process spawned handles the sequence.

bash -c "echo \
hello"

because the current bash process the lines between double quotes are joined.

what is the exact command that doesn't work ?

Upvotes: 5

Related Questions