Linux checking shell command (bash) -
how can check if shell command ends text? instance if type
$ http://example.com/file.webm (ends .webm) automatically replaced
$ wget http://example.com/file.webm of course if command consists of 1 part.
i'm using bash shell.
bash 4 provides hook handling "command not found" error. in case, http://example.com/file.webm not valid command, define following function in .bashrc file:
command_not_found_handle () { if [[ $1 = http://*.webm ]]; wget "$1" else return 127 fi } when attempt run url command, command_not_found_handle called url first argument. function checks if command name matches webm url, , if does, runs wget url argument. (for other unrecognized command, return 127, command still unrecognized.)
Comments
Post a Comment