Score:0

here-document with bash -c

it flag

This example script:

cat <<- EOF | bash -c
    command1 args
    command2 args
    command3 args
    command4 args
    command5 args
EOF

Returns: bash: -c: option requires an argument
How do I use bash -c with here-document?

Score:4
cn flag

You don't!

The -c is only for a script passed in as the first argument, not piped in via standard input as a heredoc does.

Instead you use -s, which can be omitted if there are no other arguments passed to the script.


Also, after replacing with -s you could also simplify:

cat <<- EOF | bash -s

to:

<<- EOF bash -s

Like most cats, the cat does nothing.

vidarlo avatar
om flag
+1 for that last sentence :D
it flag
Is the more correct and elegant syntax `bash -s <<- EOF` or `<<- EOF bash -s`?
Martin Thornton avatar
cn flag
Either is fine. I personally prefer putting `<` and `<<` before the command as it keeps the pipeline in order from left to right, though this is less common.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.