Search code examples
bashbackticksword-count

Nested backticks in bash script not working


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)


Solution

  • You're mixing ' and `

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