I'm trying to do something fairly simple, and I'm just coming up short. Here is an example variable I'm trying to work with:
20,80,443,53
The variable is just a string of ports separated by commas. I need to get those into an array.
Set IFS to , and use the read command with a here-string
IFS=, read -r -a arr <<<"20,80,443,53"
printf "%s\n" "${arr[@]}"
20
80
443
53
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With