Path: utzoo!utgpu!water!watmath!clyde!rutgers!rochester!ur-tut!ur-valhalla!badri From: badri@valhalla.ee.rochester.edu (Badri Lokanathan) Newsgroups: comp.unix.questions Subject: Expansion of variables in sh scripts Keywords: Forward quote, backword quote, double quote, auuuuuuuuugh! Message-ID: <1159@valhalla.ee.rochester.edu> Date: 14 Feb 88 04:19:40 GMT Organization: UR Dept. of Electrical Engg, Rochester NY 14627 Lines: 23 Well, after several years of shell script writing, I thought I knew everything about it, but I was wrong! Given a 2 column file of data in two columns, the columns separated by blanks. A script is desired which, among other things, searches for a word in the I column and outputs the corresponding entry in the II column. There are several ways of doing this; I want to know why the following inconsistency took place (I tried it on BSD4.3): #!/bin/sh word=$1 result=`awk "/^${word}/{print \$2}" datafile` echo $result # This outputs the entire line, rather than the entry in the II column. awk "/^${word}/{print \$2}" datafile # This outputs only the entry in the II column, as expected. ######################### END SCRIPT ########################### -- "I care about my fellow man {) badri@valhalla.ee.rochester.edu Being taken for a ride, //\\ {ames,caip,cmcl2,columbia,cornell, I care that things start changing ///\\\ harvard,ll-xn,rutgers,topaz}! But there's no one on my side."-UB40 _||_ rochester!ur-valhalla!badri