0

Script has to log everyting in it to output and to log file

Like this it works OK:

#!/usr/bin/env bash

some_command_1
((
echo "Some text (in parenthness too)"
echo "Another text without them"
) &2>1 )|tee log.txt
some_command_2
exit 0

It outputs to stdin/stderr and to log file as expected.

But this script:

#!/usr/bin/env bash

some_command_1
((
cat <<EOF
Some text (in parenthness too)
Another text without them

EOF
) &2>1 )|tee log.txt
some_command_2
exit 0

Produces an error:

warning: here-document at line 9 delimited by end-of-file (wanted `EOF')

Another text without them: command not found

./tmp.sh: line 11: EOF: command not found

ESCaping like this "(" does nothing.

Why?

Someone
  • 69
  • 6

1 Answers1

0

I believe that the problem is in the line containing ((. This double bracket has a special meaning in bash. Your script works for me in Linux if I separate the parentheses into separate lines.

#!/usr/bin/env bash

echo Start
(
(
cat <<XEOF
Some text (in parenthness too)
Another text without them

XEOF

) &2>1 )|tee log.txt
echo Stop
exit 0
DigiBat
  • 126
  • 2
  • Yes, this way "heredoc with parenthness" works as expected. Even if write'em on one line, but separate by space, like this: "( (" Thanks! – Someone Jan 07 '23 at 17:17