o comando não encontrado não funciona para o URL

3

Estou tentando configurar o comando_not_found_handle para links de URL

%> command_not_found_handle() { echo "OK"; }
%> aaaaa
OK
%> http://www.google.com
bash: http://www.google.com: No such file or directory

Então funciona para a entrada normal, mas não para links de URL, alguma idéia?

    
por daisy 17.11.2013 / 12:14

1 resposta

6

URLs são tratados como contendo subdiretórios. Por exemplo. veja isto:

$ command_not_found_handle() { echo "OK"; }
$ aaa
OK
$ aaa/bbb
bash: aaa/bbb: No such file or directory
$ 

Isto é, funciona quando você executa um comando, mas quando você executa um comando com uma barra, é provável que tente fazer bbb na pasta aaa . O mesmo acontece com os URLs - considera-se executando o comando www.google.com dentro do diretório http: .

Na página do bash man:

If the name is neither a shell function nor a builtin, and contains no slashes, bash searches each element of the PATH for a directory containing an executable file by that name. Bash uses a hash table to remember the full pathnames of executable files (see hash under SHELL BUILTIN COMMANDS below). A full search of the directories in PATH is performed only if the command is not found in the hash table. If the search is unsuccessful, the shell searches for a defined shell func‐ tion named command_not_found_handle. If that function exists, it is invoked with the original command and the original command's arguments as its arguments, and the function's exit status becomes the exit status of the shell. If that function is not defined, the shell prints an error message and returns an exit status of 127.

Ênfase minha.

    
por 17.11.2013 / 14:41