문제

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)

도움이 되었습니까?

해결책

You're mixing ' and `

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

다른 팁

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

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

COUNT=$(wc -l < "$NEWLIST")

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top