Short answer: sure, this is something that read
could hypothetically do. But bash
's implementation of read
does not have this feature, and I don't know of any POSIX-compatible shell that does, and POSIX itself does not include such a feature, although it seems like the kind of thing that an implementation could add as an extension if desired. If you like the feature enough, consider submitting a patch to bash
to add it!
It's easy enough to build validation using read
: just use a loop to read a value, check to see if it is valid, and if not, try again. You can write this as a bash function if you feel the need to do this on a regular basis.