bash: Use mapfile to create an array.
-
Take into account the main readme for this section. README first.
This is same as the shell builtin readarray, The readarray name has a better association with arrays, making it more readable in shell scripts.
The array is called MAPFILE by default. This reads in the netstat command output as an array.
$ mapfile -t < <(netstat)
You can then process the output using the array. This takes each line and checks to see if it starts with unix
$ for line in "${MAPFILE[@]}"; do if echo "$line" | grep -qi '^unix';then echo $line; fi; done
© Lightnetics 2024