1

I have some strings in $o1 and $o2 that I want to tabulate.

I saw a post on here saying to do this but it doesn't work ( Syntax error: end of file unexpected (expecting "}")).

{
cat <<EndOfOutput
$o1
$o2
EndOfOutput
} | column

Is this possible?

grawity
  • 501,077

2 Answers2

7

Yes, if you do it literally like in your post.

You have to keep in mind that heredoc terminators cannot be indented unless the heredoc is started using <<-EndOfOutput (the dash indicates that all leading tabs – not any whitespace, but only tabs – should be stripped).

Works Also works Fails Works with tabs only
{
cat <<End
$o1
$o2
End
} | column
{
cat <<End
$o1
$o2
End
} | column
{
cat <<End
$o1
$o2
End
} | column
{
cat <<-End
$o1
$o2
End
} | column

So the version you've posted without any indentation actually works perfectly fine on all shells; it's when you indent it to look nice that you would get the error.

Of course, you could save you some trouble by not using the brackets (the heredoc can be opened in the middle of a line) – or, by not having a pipe in there at all:

Works Works Works
cat <<End | column
$o1
$o2
End
column <<EndOfOutput
$o1
$o2
EndOfOutput
<<EndOfOutput column
$o1
$o2
EndOfOutput

(Heredocs are a shell-syntax feature so they don't require cat specifically.)

grawity
  • 501,077
0

This works.

column -t <<EOF
$o1
$o2
EOF