fork download
  1. #!/bin/bash
  2. s='DEVICE TYPE STATE CONNECTION
  3. wlp3s0 wifi connected My Test Connection
  4. p2p-dev-wlp3s0 wifi-p2p disconnected --
  5. enp4s0f1 ethernet unavailable --
  6. lo loopback unmanaged --'
  7. read wf_devc wf_state wf_conn < <(awk '
  8. /wifi[^-]/{
  9. r="";
  10. for(i=4;i<=NF;i++){
  11. r=r (i==4 ? "":" ") $i
  12. };
  13. print $1" "$3" "r
  14. }' <<< "$s")
  15.  
  16. echo "wf_devc=$wf_devc wf_state=$wf_state wf_conn=$wf_conn"
Success #stdin #stdout 0.01s 5516KB
stdin
Standard input is empty
stdout
wf_devc=wlp3s0 wf_state=connected wf_conn=My Test Connection