How to quote a shell variable in a TCL-expect string

jmac picture jmac · Feb 14, 2011 · Viewed 9.7k times · Source

I'm using the following awk command in an expect script to get the gateway for a particular destination

route | grep $dest | awk '{print $2}'

However the expect script does not like the $2 in the above statement.

Does anyone know of an alternative to awk to perform the same function as above? ie. output 2nd column.

Answer

Alex picture Alex · Feb 14, 2011

You can use cut:

route | grep $dest | cut -d \  -f 2

That uses spaces as the field delimiter and pulls out the second field