I am not understanding how this doesn't work:
ls /sys/class/net/wlan0
addr_assign_type broadcast device flags iflink netdev_group queues
subsystem uevent addr_len carrier dormant ifalias link_mode **operstate**
speed tx_queue_len address dev_id duplex ifindex mtu power statistics
for f in $(ls /sys/class/net/); do $(cat /sys/class/net/${f}/operstate); done
cat: /sys/class/net/eth0/operstate: No such file or directory
cat: /sys/class/net/lo/operstate: No such file or directory
cat: /sys/class/net/wlan0/operstate: No such file or directory
I guess $f is not expanded in time for cat
. I tried with quotes, like "$f", but still it didn't work.
This does work OK:
for f in $(ls /sys/class/net/); do echo /sys/class/net/${f}/operstate; done
/sys/class/net/eth0/operstate
/sys/class/net/lo/operstate
/sys/class/net/wlan0/operstate
And:
cat /sys/class/net/eth0/operstate
up
What have I missed? Why can't cat
see the files in the loop?