Command substitution failure - why?

C. Linus Hicks lhicks at nc.rr.com
Sun Nov 14 22:51:54 UTC 2004


On Sun, 2004-11-14 at 15:56 -0600, Vidiot wrote:
> I'm using zsh/
> 
> When I enter the following on the command line, I get the expected result:
> 
> 	echo ann001.jpg | awk "{ print substr(\$0, 1, length(\$0) -7 ) }"
> 
> Expect result = ann
> 
> But, when I do this:
> 
> 	OUT=`echo ann001.jpg | awk "{ print substr(\$0, 1, length(\$0) -7 ) }"`
> 
> I get back nothing.  The variable is empty.

I believe zsh will behave the same as bash:

[linush at lh4 ~]$ set -x
++ echo -ne '\033]0;linush at lh4:~\007'
[linush at lh4 ~]$ OUT=`echo ann001.jpg | awk "{ print substr(\$0, 1, length(\$0) -7 ) }"`
++ awk '{ print substr(bash, 1, length(bash) -7 ) }'
++ echo ann001.jpg
+ OUT=
++ echo -ne '\033]0;linush at lh4:~\007'

Notice that your "$0" was getting substituted with the wrong thing. I
changed your double quotes to single so it won't get interpreted by the
shell:

[linush at lh4 ~]$ OUT=`echo ann001.jpg | awk '{ print substr(\$0, 1, length(\$0) -7 ) }'`
++ awk '{ print substr($0, 1, length($0) -7 ) }'
++ echo ann001.jpg
+ OUT=ann
++ echo -ne '\033]0;linush at lh4:~\007'





More information about the redhat-list mailing list