Path: utzoo!utgpu!water!watmath!clyde!rutgers!umd5!trantor.umd.edu!chris From: chris@trantor.umd.edu (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: Expansion of variables in sh scripts Keywords: Forward quote, backword quote, double quote, auuuuuuuuugh! Message-ID: <2298@umd5.umd.edu> Date: 14 Feb 88 09:51:33 GMT References: <1159@valhalla.ee.rochester.edu> Sender: ris@umd5.umd.edu Reply-To: chris@trantor.umd.edu (Chris Torek) Organization: University of Maryland, College Park Lines: 23 In article <1159@valhalla.ee.rochester.edu> badri@valhalla.ee.rochester.edu (Badri Lokanathan) writes: >#!/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. Yes. Shell (sh, not csh) quoting is very easy to explain. "" quotes against file expansion; '' quotes against all expansion. Any time a line is evaluated, one level of quoting is removed. Backquotes evaluate the text inside the backquotes once. Hence "\$2" becomes $2 becomes nothing, and awk prints the whole line. Note that this means you can use backquotes inside backquotes: foo=`eval echo \`basename ...\`` This is not directly possible in csh. -- In-Real-Life: Chris Torek, Univ of MD Computer Science, +1 301 454 7163 (hiding out on trantor.umd.edu until mimsy is reassembled in its new home) Domain: chris@mimsy.umd.edu Path: not easily reachable