mainThe GNU Bourne-Again SHell - Support: sr #110544, alias named...


sr #110544: alias named 'command_not_found_handle' not recognized

Submitter:  Dominik Kummer <domson>
Submitted:  Fri 24 Sep 2021 08:57:54 AM UTC
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup

Jump to the original submission

Sun 03 Oct 2021 04:21:23 PM UTC, comment #6: 

Dear Chet,
I am currently not sure if we are on the same page on this topic. I'll try to come up with a code proposal on git as soon as possible.
Ars Longa, Vita Brevis. that's for sure unfortunately.

Dominik Kummer <domson>
Sat 25 Sep 2021 08:29:17 PM UTC, comment #5: 

OK, now what would this "magic hashtable" do that the existing code doesn't? And if you're saying that it would find the command where the existing command $PATH search code would not, how would it do that?

I already explained why the hook gets run in the child process context: so it inherits the variable assignments, redirections, and environments that the command would have had had it been found.

Since it runs in the child process, it doesn't make any sense to run it back through expansion again -- the words have already been expanded. It executes the shell function directly.

Chet Ramey <chet>
Group administrator
Fri 24 Sep 2021 10:53:50 PM UTC, comment #4: 

my expectation was more a sort of a belief. some magic hashtable behind the scenes taking into account functions and aliases. Fortunately architecture is far from a belief system...

Anyways, what concerns calling NOTFOUND_HOOK not with execute_shell_command, but execute_simple_command?
Isn't it like
(command_not_found_hook) vs. {command_not_found_hook} ?

Dominik Kummer <domson>
Fri 24 Sep 2021 09:52:18 PM UTC, comment #3: 

OK. Why would you expect bash to run that alias automatically? It's not documented to do that anywhere.

The function gets run in the child process context because that allows it to find or fetch the intended command and execute it directly, without the shell having to rewind and then re-execute the redirections and variable assignments, including their side effects (which would be a no-no).

Chet Ramey <chet>
Group administrator
Fri 24 Sep 2021 07:14:03 PM UTC, comment #2: 

Actually I expected Bash to run the aliased command in "main" scope of the script.

for example:

   $ alias command_not_found_handle='source ~/bash.handle $@'
   $ some_command # which is yet unknown

So basically I expected bash to run `source ~/bash.handle some_command` silently in background and try to find the command beyond $PATH.

The issue with command_not_found_handle as function is, that everything happens inside the scope of the function in a subshell.

I still dream of dynamic sourcing... I'll try to implement it in bash source code.

Dominik Kummer <domson>
Fri 24 Sep 2021 06:13:56 PM UTC, comment #1: 

What did you expect it to do?

Bash looks for and executes a shell function with that name if a command isn't found in a $PATH search, but an alias with that name is nothing special.

It can be executed as a command like any other alias, but has no special meaning.

Chet Ramey <chet>
Group administrator
Fri 24 Sep 2021 08:57:54 AM UTC, original submission:  

I tried to do a

$ alias command_not_found_handle='source not_found $@'

but unfortunately it does not work. is this intentional?

Best wishes

Dominik Kummer

Dominik Kummer <domson>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by domson (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-09-24 chet StatusNone Invalid

    Back to the top

    Powered by Savane 3.12.
    Corresponding source code