[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Arithmetic evaluation / expansion question
From: |
Andy Chu |
Subject: |
Re: [Help-bash] Arithmetic evaluation / expansion question |
Date: |
Wed, 10 Oct 2018 09:56:27 -0700 |
In the statement
echo $(( pd ))
pd is parsed as a variable name, not a "string". So your question really
reduces to the first thing you mentioned -- undefined variables are coerced
to 0 in arithmetic contexts.
I am working on a bash compatible shell that warns you about this, and
provides the option for it to be a fatal error with 'set -o strict-arith'.
It's not done but it handles this case well, and I appreciate other bug
reports.
http://www.oilshell.org/
bash$ bin/osh
osh$ echo $(( undef ))
Line 1 of '<interactive>'
echo $(( undef ))
^~~~~
osh warning: Coercing undefined value to 0 in arithmetic context
0
osh$ echo $?
0
osh$ set -o strict-arith
osh$ echo $(( undef ))
Line 4 of '<interactive>'
echo $(( undef ))
^~~~~
Coercing undefined value to 0 in arithmetic context
osh$ echo $?
1
On Wed, Oct 10, 2018 at 9:47 AM Bruce Hohl <address@hidden> wrote:
> An arithmetic evaluation / expansion question please: the man page
> indicates that base 10 is the default, and null or unset variables evaluate
> to zero.
>
> Are strings also evaluated to zero within $(( ))?
> (Except those beginning with 0 which are octals.)
>
> $ pd=abc
> $ echo $pd
> abc
> $ echo $((pd))
> 0
>
- [Help-bash] Arithmetic evaluation / expansion question, Bruce Hohl, 2018/10/10
- Re: [Help-bash] Arithmetic evaluation / expansion question,
Andy Chu <=
- Re: [Help-bash] Arithmetic evaluation / expansion question, Greg Wooledge, 2018/10/10
- Re: [Help-bash] Arithmetic evaluation / expansion question, Andy Chu, 2018/10/10
- Re: [Help-bash] Arithmetic evaluation / expansion question, Andy Chu, 2018/10/10
- Re: [Help-bash] Arithmetic evaluation / expansion question, Bruce Hohl, 2018/10/10
- Re: [Help-bash] Arithmetic evaluation / expansion question, Andy Chu, 2018/10/10
- Re: [Help-bash] Arithmetic evaluation / expansion question, Bruce Hohl, 2018/10/10
- Re: [Help-bash] Arithmetic evaluation / expansion question, Quentin L'Hours, 2018/10/10
- Re: [Help-bash] Arithmetic evaluation / expansion question, Bruce Hohl, 2018/10/10
- Re: [Help-bash] Arithmetic evaluation / expansion question, Chet Ramey, 2018/10/11
- Re: [Help-bash] Arithmetic evaluation / expansion question, Chet Ramey, 2018/10/11