Path: utzoo!attcan!telly!lethe!torsqnt!jarvis.csri.toronto.edu!mailrus!shadooby!samsung!cs.utexas.edu!ico!ism780c!richsc From: richsc@ism780c.isc.com (Rich Scott) Newsgroups: comp.unix.questions Subject: Re: Import variables in to awk. Message-ID: <36495@ism780c.isc.com> Date: 16 Nov 89 16:41:57 GMT References: <10531@thorin.cs.unc.edu> <15919@bloom-beacon.MIT.EDU> Reply-To: richsc@ism780c.UUCP (Rich Scott) Distribution: na Organization: Interactive Systems Corp., Santa Monica CA Lines: 39 In article <15919@bloom-beacon.MIT.EDU> jik@athena.mit.edu (Jonathan I. Kamens) writes: >In article <10531@thorin.cs.unc.edu> warner@unc.cs.unc.edu (Byron Warner) >writes: >>My questions is how do you import csh variables into an awk script. >>for example if I have a file called foo, which contains: >>{ >> print import,$0 >>} >> >>and I issue the command >>awk -F: -f foo /etc/passwd import='hello >>why do I get just a list of logins? Well, apparently awk wants its 'imported' variables specified on the command line *before* the datafile(s), but this isn't obvious from the manual page. Someone here told me that the argument parsing may not be done correctly. Anyway, on my system, which runs SunOS3.5, I get the desired effect (using csh) by doing: awk -F: -f foo import='hello' /etc/passwd (This is running the 4.2 or 4.3 BSD 'awk'; I can't speak for the "new" awk.) > > First of all, I have never known the C-shell to allow the syntax >"foo=bar" on a command-line to import a variable into a program. C >shell doesn't have anything like that. Umm, I don't think it's up to the shell in this case to do anything with it; it's simply an argument to the program. Perhaps Byron, if he really wants to import a C-shell variable into awk, should do: hostname% setenv VAR='hello' hostname% awk -F: -f foo.awk import=$VAR /etc/passwd The first example doesn't set any C-shell variables. ---------------- rich scott rls@i88.isc.com interactive systems corporation voice: (800) LAI-UNIX x255 (formerly lachman associates) naperville, il, usa