Use shell wildcard OR with diskutil

diskutilterminal

I have the following terminal command, which matches volumes called A001R45R, A123R45R, etc.

diskutil eraseVolume HFS+ FreshMag /Volumes/*R45R

But I also want it to match volumes called B001R4G5, B150R4G5, etc. How can I use the OR expression in the wildcard? I tried the following, but it doesn't work:

$ diskutil eraseVolume HFS+ FreshMag /Volumes/{*R45R,*R4G5}
The third parameter does not appear to be "bootable" or "nonbootable"
$ diskutil eraseVolume HFS+ FreshMag /Volumes/"{*R45R,*R4G5}"
Unable to find disk for /Volumes/{*R45R,*R4G5}

I'm using bash.

Best Answer

I figured out the answer myself. Apparently the bash version in OS X supports square brackets, but not curly brackets. Weird. It's bash 3.2.53. This command works:

diskutil eraseVolume HFS+ FreshMag /Volumes/*[R45R,R4G5]

However, in this particular case, it's actually better to use a more specific command like this:

diskutil eraseVolume HFS+ FreshMag /Volumes/[A-Z][0-9][0-9][0-9][R,L]???

It should be noted that if more than one volume matches this wildcard, the command will fail, because the wildcard expands to both filenames.