Search code examples
bashmacosherestring

Command only getting first line of multiline here string


I'm trying to pass a here string to a command that expects three values to be passed interactively. It seems like it should be simple enough, but for some reason, the program seems to only be receiving the first line of the here string properly and ignoring everything after the first \n.

Here is what I'm trying:

command <<< $'firstValue\nsecondValue\nthirdValue\n'

If anyone could tell me what I'm missing, I'd appreciate it greatly. I'm not sure if it's relevant or not, but the second value contains a space. I'm running this on a Mac.


Solution

  • It turns out that the command I was passing the here string to couldn't handle the input fast enough from the here string. I ended up using the following workaround:

    (printf 'value1\n'; sleep 2; printf 'value2\n'; sleep 2; printf 'value3\n') | command