Re: Command substitution failure - why?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@lh4 ~]$ set -x
++ echo -ne '\033]0;linush@lh4:~\007'
[linush@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@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@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@lh4:~\007'


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux