bug-bash
[Top][All Lists]
Advanced

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

Re: bash uses tmp files for inter-process communication instead of pipes


From: Greg Wooledge
Subject: Re: bash uses tmp files for inter-process communication instead of pipes?
Date: Mon, 6 Oct 2014 17:18:48 -0400
User-agent: Mutt/1.4.2.3i

On Mon, Oct 06, 2014 at 02:00:47PM -0700, Linda Walsh wrote:
> How much of the original do you want?... wait....... um...
> But the point it it should already work... I think it is trying to read
> from the network.

In the code below, you have a function that *generates* a stream of
data out of variables that it has directly in memory ("$nm") and
the contents of files that it reads from disk ("$(<"$nm"/address)").

Then you feed this output to something else that tries to parse the
fields back *out* of the stream of data, to assign them to variables
inside a loop, so that it can operate on the separate variables.

You're just making your life harder than it has to be.  Combine these
two blobs of code together.  Iterate directly over the variables as
you get them, instead of doing this serialization/deserialization step.

netdev_pat=... # (and other variable assignments)
cd "$sysnet" &&
for ifname in ...; do
    hwaddr=$(<"$ifname"/address)
    act_hw2if[$hwaddr]="$ifname"
    act_if2hw[$ifname]="$hwaddr"
done

On a side note, you are going out of your way to make your bash code look
like perl (alias my=declare and so on).  This is a bad idea.  It means
you are putting round pegs in square holes.  It's best to treat each
language as its own language, with its own style and its own strengths
and weaknesses.  All these extra layers you are introducing just make
things worse, not better.


> shopt expand_aliases
> alias dcl=declare         sub=function
> alias int=dcl\ -i         map=dcl\ -A       hash=dcl\ -A    array=dcl\ -a
> alias lower=dcl\ -l       upper=dcl\ -u     string=dcl      my=dcl
> sub get_net_IFnames_hwaddrs () {        # get names + addrs from /sys
>   vrfy_drivers
>   array pseudo_devs=(br bond ifb team)
>   string pseudo_RE="^+(${pseudo_devs[@]})$"
>   pseudo_RE=${pseudo_RE// /|}
>   string netdev_pat="+([_0-9a-z])+([0-9])"
>   sysnet=/sys/class/net
>   ( cd "$sysnet" &&
>     for nm in $( printf "%s\n" $netdev_pat | grep -Pv "$pseudo_RE"); do
>       echo "$nm" "$(<$nm/address)"
>     done )
> }
> 
> map act_hw2if                           #actual values (to be read in)
> map act_if2hw
> map XIF                                 #tmp array to hold exchanged IF's
> 
> sub read_actuals () {                   # parse output stream from above
>   my ifname hwaddr
>   while read ifname hwaddr; do
>     act_hw2if[$hwaddr]="$ifname"
>     act_if2hw[$ifname]="$hwaddr"
>   done <<<"$(get_net_IFnames_hwaddrs)"
> }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]