The 2>&1 is redirecting STDERR to the STDIN stream. The shell parses this as a single unit. If 2 were an option value to -v, that would leave >&1. This would be equivalent to >1 2>&1
, which isn't likely desired.
The first form posted:
cm=`sox infile outfile vol `sox infile -n stat -v 2>&1``
will never work because the OP is not noticing / understanding that nested quotes won't work without escaping the inner quotes. The second backquote immediately terminates the first back quote. The same for backquotes number 3 and 4, which results in at attempt to assign three components to cm:
cm=`sox infile outfile vol ` sox infile -n stat -v 2>&1``
and this is equivalent to:
$ cm=a b c
bash: b: command not found
The second form works correctly, because there is no nesting of quotes. Using set -x, we can see this (I used print "retval" to be a phony return value from the first sox):
$ set -x
$ cm=`echo sox infile outfile vol $(printf "retval" sox infile -n stat -v 2>&1)`
llline 1: printf retval sox infile -n stat -v
lline 1: echo sox infile outfile vol retval
line 14: cm='sox infile outfile vol retval'
What the OP needs to show is the exact input/output that shows the problem encountered, and not do the interpretation for us.