Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!rpi!tale From: tale@pawl.rpi.edu (David C Lawrence) Newsgroups: comp.unix.questions Subject: Re: Import variables in to awk. Message-ID: <1989Nov15.235518.8933@rpi.edu> Date: 15 Nov 89 23:55:18 GMT References: <10531@thorin.cs.unc.edu> <15919@bloom-beacon.MIT.EDU> <20774@mimsy.umd.edu> Distribution: na Organization: Rensselaer Polytechnic Institute, Troy NY Lines: 29 In <10531@thorin.cs.unc.edu> warner@unc.cs.unc.edu (Byron Warner) writes: Byron> [file foo] Byron> { print import,$0 } Byron> [command] Byron> awk -F: -f foo /etc/passwd import='hello Byron> why do I get just a list of logins? Because the variable assignment has to come before file name. I'm also assuming here that the ' is a typo, or the absence of a match is; either way variable assignment comes before the file list. If you change it to "awk -F: -f foo import=hello /etc/passwd" it will work. This applies to V7 awk, nawk and gawk. In <20774@mimsy.umd.edu> chris@mimsy.umd.edu (Chris Torek) writes: Chris> All of the above is with respect to the 4.3BSD flavour of `awk'. The Chris> new awk (as described in the awk book) appears to open the first `file' Chris> before executing the BEGIN statement, so that any assignments that Chris> appear before the first real file happen before the BEGIN. What GNU Chris> awk does, I do not know (but the above technique will tell you). Variables set as above are not available in the BEGIN block with gawk, but a special option, -v, is provided to do this. -v VAR=VAL will assign VAL to VAR before script execution begins; another -v must be specified for each variable you want to declare this way. Dave -- (setq mail '("tale@pawl.rpi.edu" "tale@ai.mit.edu" "tale@rpitsmts.bitnet"))