Get Number of Screens Using system_profiler
This can be achieved by parsing the output of system_profiler SPDisplaysDataType with this line.

system_profiler SPDisplaysDataType | grep Resolution: | wc -l

As fd0 mentioned, this can be shortened to this.

system_profiler SPDisplaysDataType | grep -c Resolution