[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: command_not_found_handle and sourced script

From: Dominique Ramaekers
Subject: Re: command_not_found_handle and sourced script
Date: Wed, 28 Dec 2016 15:35:27 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1

Op 27-12-16 om 00:23 schreef Dan Douglas:
> On Mon, Dec 26, 2016 at 12:42 PM, Dominique Ramaekers
> <address@hidden> wrote:
>> As I understand it, the command_not_found_handle is not triggered on an
>> unknown command in a shell script, run normally.
> Where'd you here that? That's easy to test.
>  $ bash <<<'command_not_found_handle () { echo "$FUNCNAME"; }; blah'
> command_not_found_handle
> Doesn't seem to matter.

When I do this test...
$function command_not_found_handle { echo mycnf; }
$echo -e '#!/bin/bash\nlss' > test
$chmod +x test
./test: line 2: lss: command not found
$. ./test

... I first thought you were wrong.

But then I did this:
$ echo -e '#!/bin/bash\ntype command_not_found_handle' > test
$ ./test
./test: line 2: type: command_not_found_handle: not found
$ . ./test
command_not_found_handle is a function
command_not_found_handle ()
    echo mycnf

Apparently, in a non-interactive shell, the command_not_found_handle
isn't set on my system (ubuntu).

So I hope you understand my confusion earlier...

I found in .bashrc these lines:
# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;

And in /etc/bash.bashrc some similar lines.

So... You actually are completely right.

Thanks for the help, Dan.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]