This is a similar question to this one
I want to do the word count but this time, using an array.
For example, I have the following IPs inside a bash array called IPS
.
IPS=("1.1.1.1" "5.5.5.5" "3.3.3.3" "1.1.1.1" "2.2.2.2" "5.5.5.5" "1.1.1.1")
If I read its contents:
user@server~$ "${IPS[*]}"
1.1.1.1 5.5.5.5 3.3.3.3 1.1.1.1 2.2.2.2 5.5.5.5 1.1.1.1
I would like to have something similar to this:
3 1.1.1.1
2 5.5.5.5
1 3.3.3.3
1 2.2.2.2
((arr[${ip}]++))
is an arbitrary command execution vulnerability if the contents of$ip
/$IPS
is not under your control (try for instanceip='$(uname>&2)x' bash -c 'typeset -A arr; ((arr[${ip}]++))'
). You'd wantarr[$ip]=$((${arr[$ip]} + 1))
here to avoid it. – Stéphane Chazelas Sep 30 '19 at 12:25