Nested backticks in bash script not working
-
28-10-2019 - |
문제
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.
제휴하지 않습니다 StackOverflow