How do I break up an extremely long string literal in bash?

It’s a bit of a hack, but this works:

mycommand \
    --server myserver \
    --filename "extremely/long/file/name/"`
               `"that/i/would/like/to/be/able/to/break/"`
               `"up/if/possible" \
    --otherflag \
    --anotherflag

Bash concatenates string literals that are adjacent, so we take advantage of that. For example, echo "hi" "there" prints hi there whereas echo "hi""there" prints hithere.

It also takes advantage of the backtick operator, and the fact that a bunch of spaces evaluates to nothing.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)