As you have established already, the problem lies with the interpolation of the variable $3
. Instead of escaping the $
to fix the problem, this can be circumvented completely by using perl to split the output of your command.
You should be able to do something like this in perl, using split
rather than relying on awk
. Note that the $3
used in your awk
command corresponds to index number 2, due to arrays starting from index 0.
my $output = `/bin/sh $DIR/ami-show.sh Version:`;
my $column = (split ' ', $output)[2];
split
takes a regular expression as its first argument (the pattern) and splits the string contained in the second argument. The code above splits the output of the command on any amount of white space, which is the same as what awk
does by default.
edit: If you saw my first edit, I simply did split $output
, omitting the pattern argument. This is actually valid, as not specifying a pattern invokes the same, awk-like behaviour.