In bash:
$ s() { printf 'Called s %s\n' "$*" >&2; }
$ cat $HOME/bin/command_not_found_handle
#!/usr/bin/env bash
command_not_found_handle() {
if [[ "$*" =~ ^(s)([0-9]{3})$ ]]; then
"${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}"
else
printf 'Command not found: %s\n' "$*" >&2
return 127
fi
}
$ . $HOME/bin/command_not_found_handle
$ s123
Called s 123
$ s500
Called s 500
$ echo $?
0
$ s5001
Command not found: s5001
$ echo $?
127
FYI 127 is the standard "command not found" exit status. See https://www.gnu.org/software/bash/manual/bash.html#Command-Search-and-Execution for more information.
I'm only using BASH_REMATCH[] as above to call s because I know it's safe to do so given that $* contains the command as a single letter and its args just 3 digits, for anything more complicated see https://mywiki.wooledge.org/BashFAQ/050.
There is no solution that will work in every shell, see How to define a function that handles `command not found`? to find information on approaches to the above for some other shells.