How to list all /dev/disks, not partitions ending in s1, s2, …

bashcommand line

I am trying to list (output) the drive its Mac OS X name from the serial number in the Bash 3.2 shell on the command line. For this I need to loop through all block devices not being a partition. So I need a better replacement for this bash loop: for disk in /dev/disk*; do …; done

I do want to use ls only, eventually with a wildcard pattern, without piping (through grep) and without other utils (like find).

It is like ls /dev/disk* but not matching the partitions ending in s1 (like /dev/disk0s1), s2 etcetera.

Regression

The failing attempts:

$ ls /dev/disk[0-9]*[!s][!1-9]
$ ls /dev/disk[0-9]*[!s,!1-9]
$ ls /dev/disk* -d -- *[!s][1-9]
$ ls /dev/disk[0-9]*[!s,1-9]
$ ls /dev/disk[0-9]*[!s]
$ ls /dev/disk[0-9]*[!s][0-9]
$ ls /dev/disk[0-9]*[!s]*
$ ls /dev/disk[0-9]*[!\s1-9]
$ ls /dev/disk[0-9]*[!s1-9]
$ ls /dev/disk[0-9]*([!s1-9])
$ ls /dev/disk[0-9]*[!s]*[0-9]
$ ls /dev/disk[0-9][0-9]
$ ls /dev/disk* --ignore="disk*s?"
$ ls /dev/disk* -I "*s?"
$ ls /dev/disk* -I "*s[1-9]"
$ ls /dev/disk*[!s?]

Best Answer

Using ksh's extended glob:

ls /dev/+(disk?|disk??)

for bash you have to turn on extended glob

shopt -s extglob
ls /dev/+(disk?|disk??)