I am trying to read a string literal into stdin using the following method:
#!/usr/bin/env bash
set -e;
gmx --stdin < `cat <<EOF
node e "console.log('foo')"
EOF`
when I run this, I get this error:
simple.sh: line 5: `cat <<EOF
node e "console.log('foo')"
EOF`: ambiguous redirect
If I get rid of the backticks,
gmx --stdin < cat <<EOF
node e "console.log('foo')"
EOF
I get this error:
/simple.sh: line 5: cat: No such file or directory
anyone know how to fix? If it's unclear what I am trying to do - I am just trying to read a string literal into the stdin of the gmx process.
I also tried this:
gmx --stdin <<< node e "console.log('foo')"
but that didn't seem to work, I might need to put the node command in quotes, which sort defeats the purpose of what I am trying to do. I am looking to include shell variables in the command - HEREDOC is nice because I don't need to escape " characters.
cat <<< "echo "444""
the problem is that I have to surround the echo command with double quotes, I am looking to avoid that so I don't have to escape the double quotes. Heredoc would allow me to avoid, but now sure how to do it. – Alexander Mills May 06 '18 at 20:58echo node -e $'"console.log(\'foo\')"'
and pass it togmx --stdin
? Try that with pipe,echo node -e $'"console.log(\'foo\')"' | gmx --stdin
. Alternatively,gmx --stdin <<< "$(echo node -e $'"console.log(\'foo\')"' )"
– Sergiy Kolodyazhnyy May 06 '18 at 20:58