1

I'm trying the following in a bash script:

COUNT=`cat "$NEWLIST" | wc -l | awk \' { print $1 } \` `

where NEWLIST is a string containing a list of files, one per line. But I get this error:

command substitution: line 74: unexpected EOF while looking for matching `''

Why is that failing? How do I use nested backticks?

(basically I'm trying to strip whitespace from the result of wc, but I'd also like to know how to use nested backticks anyways)

mark
  • 4,678
  • 7
  • 36
  • 46

3 Answers3

8

That's one reason you should use $() instead of backticks.

Also, there's no need for cat or AWK:

COUNT=$(wc -l < "$NEWLIST")
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • Thanks. I was originally using awk because in my Mac OSX terminal, wc was producing leading whitespace. But it seems to be gone with the above expression. – mark Mar 22 '11 at 05:49
2

That second "escaped backtick" should actually be a single quote, just like the first one. Also, be careful with the $1 there.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
2

You're mixing ' and `

COUNT=`cat "$NEWLIST" | wc -l | awk ' { print $1 } ' `
Erik
  • 88,732
  • 13
  • 198
  • 189