Re: BUG??

2016-12-28 Thread Chet Ramey
On 12/28/16 8:09 PM, Peter & Kelly Passchier wrote:
> Is this a bug? These both output "q=1"
> 
> q=1
> [[ ((q==1)) ]] && echo q=1
> 
> q=0
> [[ ((q==1)) ]] && echo q=1
> 

No. These both end up checking whether the length of the string "q==1" is
non-zero, which it is.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: BUG??

2016-12-28 Thread Charles Daffern
On 29/12/16 01:09, Peter & Kelly Passchier wrote:
> Is this a bug? These both output "q=1"
>
> q=1
> [[ ((q==1)) ]] && echo q=1
>
> q=0
> [[ ((q==1)) ]] && echo q=1
>
>
This looks like an incorrect use of [[/((. The correct phrasing would be:


q=1

((q==1)) && echo q=1

q=0

((q==1)) && echo q=1


By wrapping it in the [[ operator, instead of running ((...)) as a
command, you're testing whether it is a string of nonzero length (and it
always is, since you have it typed right there). The ((...)) operator
alone is sufficient to make the test you want to make.


It could also be phrased as:


q=1

[[ $q -eq 1 ]] && echo q=1

q=0

[[ $q -eq 1 ]] && echo q=1


In the bash man page, under the SHELL GRAMMAR section is a description
of the [[ operator, which should shed some further light on why this
behaves as it does.




signature.asc
Description: OpenPGP digital signature


BUG??

2016-12-28 Thread Peter & Kelly Passchier
Is this a bug? These both output "q=1"

q=1
[[ ((q==1)) ]] && echo q=1

q=0
[[ ((q==1)) ]] && echo q=1



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.