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

Re: No ifconfig [Was: no /etc/inittab]



On Wed, Aug 16, 2017 at 11:58:06AM +0200, tomas@tuxteam.de wrote:
>   oldIFS="$IFS"; IFS=': '; ip -o link | while read num interface other;
>     do echo "$interface"; done; IFS="$oldIFS" 

ip -o link | while IFS=' :' read -r _ i _; do echo "<$i>"; done

There's no need to set IFS globally and then attempt to restore it,
especially since "restoring" it fails if it was previously unset.
Just set it for the duration of the read command.

The alternative is to make IFS local, within a function:

foo() {
  local IFS=' :'
  ip -o link | while read -r _ i _; do echo "<$i>"; done
}
foo

But once again, this is overkill, when IFS only needs to be modified in
the execution environment of the read command.  (Also less portable,
because POSIX shell functions don't necessarily have "local".)


Reply to: