help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] A do nothing function


From: DJ Mills
Subject: Re: [Help-bash] A do nothing function
Date: Fri, 28 Sep 2012 11:23:41 -0400

On Fri, Sep 28, 2012 at 8:13 AM, Greg Wooledge <address@hidden> wrote:
> On Thu, Sep 27, 2012 at 03:35:51PM -0600, Bob Proulx wrote:
>>   filter=cat
>>   if [ -f tun0.net ]; then
>>     filter="sed /^eth/d;/^wlan/d;/^NetworkManager/d"
>>   fi
>>   RSLVCNFFILES="$(/lib/resolvconf/list-records | $filter | sed -e '/^lo$/d' 
>> -e '/^lo[.]/d')"
>
> Using a function would be more flexible, and less likely to break:
>
> filter() { cat; }
> if [ -f tun0.net ]; then
>   filter() { sed /^eth/d;/^wlan/d;/^NetworkManager/d; }
> fi
> RSLVCNFFILES="$(/lib/resolvconf/list-records | filter | ...)"
>

I think I'd put the condition in the function:
filter() {
  if [ -f tun0.net ]; then
    sed '/^eth/d; /^wlan:/d; /^NetworkManager/d'
  else
    cat
  fi
}

blah=$(foo | filter | ....)



reply via email to

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