Re: Command substitution failure - why?

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

 



On 17:51 14 Nov 2004, C. Linus Hicks <lhicks@xxxxxxxxx> wrote:
| On Sun, 2004-11-14 at 15:56 -0600, Vidiot wrote:
| [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'

And this is because backticks add another layer of sloshing.

You can try using the $() syntax, thus:

	OUT=$(echo ann001.jpg | awk '{ print substr(\$0, 1, length(\$0) -7 ) }')

it has the advantage of not introducing a new level of sloshing because the
$(...) stuff nests nicely.
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

It is interesting to think of the great blaze of heaven that we winnow
down to animal shapes and kitchen tools.        - Don DeLillo

-- 
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