arr=($(screen -ls | egrep -o '\t.+\t' | sort -n))
arr=($(...)): Assigns a series of whitespace-delimited values to an indexed array, e.g.
arr=($(1 2 three 4)) defines
screen -ls: The base function whose output is to be filtered. This outputs the following (example) lines:
There are screens on:
3 Sockets in /var/folders/ht/0ty_c8mx16v69csh949g3rvr0000gn/T/.screen.
Note that the white-space on the lines containing the session details are tab-delimited columns.
egrep -o '\t.+\t': Selects only the output on each line that falls between two tab characters (includes the tabs). This isolates the
sort -n: Sort each line by numerical order, from smallest pid to greatest pid.
The resulting array contains the
pid.tty.host identifiers for each screen session (both attached and detached), with
$arr containing the session that started first, through to
$arr[n-1] containing the nth session, started most recently.