[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Error message garbage when parameter expansion used inside (()) and
From: |
PRussell |
Subject: |
Re: Error message garbage when parameter expansion used inside (()) and variable unset |
Date: |
Tue, 3 Apr 2018 12:15:14 -0500 |
Chet, is the output on opensuse running bash 4.4.19, correct?
The specific output:
./t.sh: line 9: ���#V: var1 == : syntax error: operand expected (error
token is "== ")
archlinux has the same version of bash and I got the same results as on
opensuse.
Below are the details of running ./t.sh &>t.log on multiple versions of
bash.
When I run this script (t.sh),
......................
#!/bin/bash
# system info
lsb_release -d
printf -- 'Bash Version: %s\n\n' "${BASH_VERSION}"
# test example
echo 3B
( set -x; var=0;var1=var; (( var1 == $var2 )) && echo yes || echo no )
......................
I get,
......................
Description: openSUSE Tumbleweed
Bash Version: 4.4.19(1)-release
3B
+ t.sh line 9 : var=0
+ t.sh line 9 : var1=var
+ t.sh line 9 : (( var1 == ))
./t.sh: line 9: ���#V: var1 == : syntax error: operand expected (error
token is "== ")
+ t.sh line 9 : echo no
no
......................
......................
Description: Linux Mint 17.3 Rosa
Bash Version: 4.3.11(1)-release
3B
+ t.sh line 9 : var=0
+ t.sh line 9 : var1=var
+ t.sh line 9 : (( var1 == ))
./t.sh: line 9: var1 == : var1 == : syntax error: operand expected
(error token is "== ")
+ t.sh line 9 : echo no
no
......................
If I remove the "set -x" I get,
......................
Description: openSUSE Tumbleweed
Bash Version: 4.4.19(1)-release
3B
./t.sh: line 9: ((: var1 == : syntax error: operand expected (error
token is "== ")
no
......................
......................
Description: Linux Mint 17.3 Rosa
Bash Version: 4.3.11(1)-release
3B
./t.sh: line 9: ((: var1 == : syntax error: operand expected (error
token is "== ")
no
......................
--
Peggy Russell
On 04/03/2018 08:49 AM, Chet Ramey wrote:
On 4/2/18 5:16 PM, PRussell wrote:
Section 6.5 Shell Arithmetic says,
"Within an expression, shell variables may also be referenced by name without
using the parameter expansion syntax. A shell variable that is null or unset
evaluates to 0 when referenced by name without using the parameter expansion
syntax." - http://www.gnu.org/software/bash/manual/bash.html#Shell-Arithmetic
The above tells us what happens to an unset variable if not using parameter
expansion.
But if a shell variable uses parameter expansion and is null or unset, what
does it evaluate to inside (()) syntax?
Since ((...)) is equivalent to let "...", as noted in the description of
`((' in the man page and info doc, it expands to the same thing that it
would when you perform a double-quoted word expansion. If you expand a
shell variable that's null or unset, you get the usual: it disappears.
The problem is what is happening with 3B and 4B. I tested on bash 4.3.11 and
bash 4.4.19 and got a slightly different error message.
Bash version 4.3.11:
./tt: line 18: var1: var1 == : syntax error: operand expected (error token is "==
")
Bash version 4.4.19 (???? was garabage):
./tt: line 18: ????: var1 == : syntax error: operand expected (error token is "==
")
I don't get this. I get `((' as the command name in the error message for
both bash-4.3.46 and bash-4.4.19:
./x18: line 1: ((: var1 == : syntax error: operand expected (error token
is "== ")
- Error message garbage when parameter expansion used inside (()) and variable unset, PRussell, 2018/04/02
- Re: Error message garbage when parameter expansion used inside (()) and variable unset, Greg Wooledge, 2018/04/03
- Re: Error message garbage when parameter expansion used inside (()) and variable unset, Daniel Mills, 2018/04/03
- Re: Error message garbage when parameter expansion used inside (()) and variable unset, Chet Ramey, 2018/04/03
- Re: Error message garbage when parameter expansion used inside (()) and variable unset,
PRussell <=
- Re: Error message garbage when parameter expansion used inside (()) and variable unset, Greg Wooledge, 2018/04/03
- Re: Error message garbage when parameter expansion used inside (()) and variable unset, Chet Ramey, 2018/04/03
- Re: Error message garbage when parameter expansion used inside (()) and variable unset, PRussell, 2018/04/03
- Re: Error message garbage when parameter expansion used inside (()) and variable unset, Chet Ramey, 2018/04/04
- Re: Error message garbage when parameter expansion used inside (()) and variable unset, Chet Ramey, 2018/04/04