When in bash some non existing command is run, corresponding error message appears:
$ non-existent-command
non-existent-command: command not found
Is it possible to customize this behavior?
I would like to achieve the following. When the entered command matches, for example, the pattern s\d\d\d, it should be handled specially:
sshould be extracted and used as a command,\d\d\dshould be extracted and used as an argument for thescommand.- The command created by parsing the above should be run.
This can normally be achieved by means of a function named s that takes the needed arguments. A normal call is used to run such a function. For example:
s 123
But I want to customize the behavior of bash to be able to run such a function with, for example, the following calls:
s123s500
I tried to find related information in man bash by the following keywords: overload, custom, override and did not succeed.
As I understand it, I need to somehow customize the bash handler that is used for processing input. I did not investigate bash source code to understand if this is feasible.
It will be best to come up with solution that is usable for any shell.
Probably creating a custom bash wrapper/adapter with the needed logic and using it instead of standard bash binary will solve this.
command_not_found_handle- see Command Search and Execution. This previous question (although zsh focused) might be a good starting point: How to define a function that handlescommand not found?1register the shortcut should bes1(short for save to1). To switch to this directory later corresponding shortcut should bel1(short for load from1). Registers can be[0-9a-z]as one char or longer. Existing interfering commands likelsshould keep their standard behavior. If you familiar with the idea ofVim marksthey will be good illustration.bashmeans this can be implemented withs 1,l 1function calls. But this will 1) occupylcommand which I want to continue to use aslessalias:alias l='ls -lhA', 2) require to add one more keystrokes (constant typing of space character).for i in {1..999}; do alias "l$i=\l $i"; donein your shell startup file? (The backslash prevents it using your alias forl, which could continue to be aliased toless.)