|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I tried to connect an awk job to a bash script using two fifos. The idea
was that the script should send requests to awk over one pipe and get results back over the other one. I tested that with a simple awk script providing access to an associative array: # t.awk { switch ($1) { case "set": arr[$2] = $3 case "get": print arr[$2] case "quit": exit } } The bash script was #t mkfifo in mkfifo out awk -f t.awk <in >out & echo "set one 111" >in echo "set two 222" >in echo "get one" >in read x <out echo "one=$x" echo "get two" >in read x <out echo "two=$x" echo "set one XXX" >in # line 22 echo "get one" >in read x <out echo "one=$x" echo "quit" >in The output I expected was one=111 two=222 one=XXX but instead this happened: one=111 two= ./t: line 22: in: Interrupted system call It seeems that awk exits right after the first print. Can anybody explain that? And is there a way to keep awk reading? If awk is replaced by a bash script which mimics the array functionality, everything works fine. Regards, Bernd -- Bernd Eggink monoped@sudrala.de http://autojar.sourceforge.de http://jboom.sourceforge.de |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Bernd Eggink wrote:
> I tried to connect an awk job to a bash script using two fifos. The idea > was that the script should send requests to awk over one pipe and get > results back over the other one. > > I tested that with a simple awk script providing access to an > associative array: > > # t.awk > { > switch ($1) > { > case "set": arr[$2] = $3 > case "get": print arr[$2] > case "quit": exit > } > } What awk version is it that supports switch/case statements? Janis > [snip] |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
In article <f7g1k1$88q$1@online.de>,
Janis Papanagnou <Janis_Papanagnou@hotmail.com> wrote: >What awk version is it that supports switch/case statements? gawk has supported this for some time, if its build is configured with --enable-switch. John -- John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/ |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Mon, 16 Jul 2007 16:51:16 +0200, Bernd Eggink
<monoped@sudrala.de> wrote: > > > I tried to connect an awk job to a bash script using two fifos. The idea > was that the script should send requests to awk over one pipe and get > results back over the other one. > > I tested that with a simple awk script providing access to an associative > array: > > # t.awk > { > switch ($1) > { > case "set": arr[$2] = $3 > case "get": print arr[$2] > case "quit": exit > } > } > > The bash script was > #t > > mkfifo in > mkfifo out > awk -f t.awk <in >out & > echo "set one 111" >in > echo "set two 222" >in > > echo "get one" >in > read x <out > echo "one=$x" > > echo "get two" >in > read x <out > echo "two=$x" > > echo "set one XXX" >in # line 22 > echo "get one" >in > read x <out > echo "one=$x" > > echo "quit" >in > > The output I expected was > > one=111 > two=222 > one=XXX > > but instead this happened: > > one=111 > two= > ./t: line 22: in: Interrupted system call > > It seeems that awk exits right after the first print. Can anybody explain > that? And is there a way to keep awk reading? > Awk exits when it gets EOF on its last input file and completes the END block if there is one. Maybe this will work: tail -f in | awk -f t.awk > out & > If awk is replaced by a bash script which mimics the array functionality, > everything works fine. > > Regards, > Bernd > -- "All my life I wanted to be someone; I guess I should have been more specific." -- Jane Wagner |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Bill Marcum schrieb:
> Awk exits when it gets EOF on its last input file and completes the END > block if there is one. > Maybe this will work: > tail -f in | awk -f t.awk > out & Not really: one=111 two= ../t: line 24: out: Interrupted system call one= The question is, why does awk think it gets EOF though there is none yet? Bernd -- Bernd Eggink monoped@sudrala.de http://autojar.sourceforge.de http://jboom.sourceforge.de |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
2007-07-16, 16:51(+02), Bernd Eggink:
> I tried to connect an awk job to a bash script using two fifos. The idea > was that the script should send requests to awk over one pipe and get > results back over the other one. > > I tested that with a simple awk script providing access to an associative > array: > > # t.awk > { > switch ($1) > { > case "set": arr[$2] = $3 > case "get": print arr[$2] > case "quit": exit > } > } > > The bash script was > #t > > mkfifo in > mkfifo out > awk -f t.awk <in >out & > echo "set one 111" >in > echo "set two 222" >in You mention >in twice, so you open the pipe for writing twice. Try: { echo "set one 111" echo "set two 222" } > in instead. But you should leave the fd to in open as long as you want to write to it in a single session, otherwise, awk will see EOF, each time you close the writer side. -- Stéphane |
|
![]() |
| Outils de la discussion | |
|
|