[Top][All Lists]

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

Re: Command substitution with null bytes generates warning

From: Greg Wooledge
Subject: Re: Command substitution with null bytes generates warning
Date: Tue, 20 Sep 2016 15:53:02 -0400
User-agent: Mutt/

On Tue, Sep 20, 2016 at 12:17:37PM -0700, L. A. Walsh wrote:
> /sys/class/net/br0> /tmp/showvals
> addr_assign_type:              1
> addr_len:                      6
> address:                       00:15:17:bf:be:b2
> /tmp/showvals: line 63: printf: `invalid format character
> brforward:                    '`f#?? 
> 7ridge/ageing_time:            30000
> bridge/bridge_id:              8000.001517bfbeb2

So you are just "catting" each file in the current working directory?
Or maybe you just want the first "line" of each file?

Why not simply do:

address@hidden:/sys/class/net/eth0$ for f in *; do [[ -f $f ]] || continue; 
read -r line < "$f" 2>/dev/null; [[ $line ]] && printf '%-25.25s %s\n' "$f:" 
"$line"; done
addr_assign_type:         0
address:                  6c:3b:e5:2b:f7:19
addr_len:                 6
broadcast:                ff:ff:ff:ff:ff:ff
carrier:                  1
carrier_changes:          2

Your example script didn't even *have* a command substitution with a
NUL-byte-containing file in it, as far as I could tell.  Of course,
the script was 20 times as large & complex as it needed to be, so I
might have missed some crazy dynamically-constructed thing.

(If you also want it to show the contents of subdirectories, then it
becomes slightly larger.  I won't bother writing that one out.)

reply via email to

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