Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!snorkelwacker!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions Subject: Re: Import variables in to awk. Message-ID: <15919@bloom-beacon.MIT.EDU> Date: 15 Nov 89 10:35:39 GMT References: <10531@thorin.cs.unc.edu> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Distribution: na Organization: Massachusetts Institute of Technology Lines: 30 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? >Thanx in Advance 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. Second, the only way to do what you want is to actually make the creation of this variable part of the awk script. Like this: % set import = 'hello' % awk 'BEGIN { import = "'"$import"'" } { print import, $0}' /etc/passwd The $import is evaluated before awk is actually called, and replaced by 'hello' (sans quotes). Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8495 Home: 617-782-0710