The bash implementation on MacOS 13.6.1 is: % /bin/sh --version GNU bash, version 3.2.57(1)-release (arm64-apple-darwin22) Copyright (C) 2007 Free Software Foundation, Inc. This fails to handle 'case' inside of $(). Reimplement using if/elif/fi.