[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] bash/awk question



> I understand the correct way to do this is probably awk, 
or perl or sed or ...
but i would use awk, too :-)

> but not sure how to make it work in this case. For example, I
> could put the code in a bash function, but then how do I
> access the function from inside the awk command?
you could only call another script from inside the awk script.

> The key thing
> here is that my /bin/sh code has variables which I would like
> to read/write from inside the loop. 
this is basically impossible. environment variables are inherided by
children, but cannot be given back.
a nice workaround for this is something like that:

#! /bin/bash

bashfn() {
  eval $(awk '{print "var=val1 var2=\"this is a value\""}')
}

bashfn
echo $var $var2


works pretty well ...
remember to export the variables, if they need to be inherited by called 
progs.

good luck!

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Real programmers don't comment their code.
It was hard to write, it should be hard to understand.
--
Become part of the world's biggest computer cluster - 
join http://www.distributed.net/



Reply to: