0

I'm trying to wrap my head around nested command substitution. I tried nesting backticks but obviously that doesn't work. How would you nest the following without declaring the ${host} variable first?

host=$(hostname|cut -c1-14);for id in `aladmin list|grep ${host}|awk '{print $2}'`;do aladmin delete ${id};done

The command lists all alarms on a server, greps for the first 14 characters of the hostname and then deletes the alarm with the alarm ID found in field 2 by awk.

My question does in no way duplicate the 'hello' in previous post: How to properly nest Bash backticks

Thanks in advance, Bjoern

Bjoern
  • 1
  • 2

1 Answers1

0

Do everything in awk. There's no need to use the for loop and the grep, etc. There are better ways than this, but as a first approximation, try something like:

aladmin list | awk "/$(hostname | cut -c1-14)/"'{ print "aladmin delete " $2 | "sh"}'
William Pursell
  • 204,365
  • 48
  • 270
  • 300