1

I have the statement:

A=$(echo "echo a") && bash -c "awk -v var=\"$A\" 'BEGIN {printf \"%20s\", var}'"

Which outputs:

          echo az

And I can't make this one-liner work:

A=$(echo "echo a") && bash -c "paste <(awk -v var="$A" 'BEGIN {printf \"%-200s\n\", var}') <(echo "BBBB") --delimiters ''"

a 'BEGIN {printf "%-200s\n", var}') <(echo BBBB) --delimiters '': -c: line 0: unexpected EOF while looking for matching `)'
a 'BEGIN {printf "%-200s\n", var}') <(echo BBBB) --delimiters '': -c: line 1: syntax error: unexpected end of file

I presume this is because "$A" is not treated as a variable. Can someone explain this to me. Thanks!

1 Answers1

3

This seems to be working:

A=$(echo "echo a") && bash -c "paste <(awk -v var=\"$A\" 'BEGIN { printf \"%s\", var }') <(echo 'BBBB')"

But, I beg you, don't ever write anything like this. Its just plain gross, it makes people's eyes bleed. Please, use a real programming language like Ruby/Python/Perl if your shell scripts are becoming more complex then a list of commands and few "if" statements and/or are longer then can fit on one screen. Otherwise it would be so much FUN to debug and support these later or for someone else.

Dmitry Ilyin
  • 573
  • 2
  • 5