Re: command_not_found_handle and sourced script

2016-12-28 Thread Dominique Ramaekers

Op 27-12-16 om 00:23 schreef Dan Douglas:
> On Mon, Dec 26, 2016 at 12:42 PM, Dominique Ramaekers
>  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
./test: line 2: lss: command not found
$. ./test
mycnf

... 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;;
esac

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

So... You actually are completely right.

Thanks for the help, Dan.





Re: command_not_found_handle and sourced script

2016-12-26 Thread Dan Douglas
On Mon, Dec 26, 2016 at 12:42 PM, Dominique Ramaekers
 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.

> To my opinion, a sourced script (once debuged) shouldn't contain unknown
> commands. So the command_not_found_handle is not necessary.

It may. A shell script may be run in any unknown environment which may
not have the available commands in PATH or elsewhere. Originally
command_not_found_handle was added for features like ubuntu's default
package suggestions when run interactively, but it has been used for
other purposes.



command_not_found_handle and sourced script

2016-12-26 Thread Dominique Ramaekers

Hi,

I have a philosophical question regarding the function of the 
command_not_found_handle...


As I understand it, the command_not_found_handle is not triggered on an 
unknown command in a shell script, run normally.


Dough, it is triggered on an unknown command in a sourced script.

Is there a philosophy behind that?

To my opinion, a sourced script (once debuged) shouldn't contain unknown 
commands. So the command_not_found_handle is not necessary.


Greetings,

Dominique.