Files

52 lines
1.2 KiB
Plaintext

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# test expression evaluation with unset variables
set -u
( echo $(( a > 4 )) ; echo after 1 ) # error
( echo $(( a[0] > 4 )); echo after 2) # error
set +u
( echo $(( a > 4 )) ; echo after 3 $? )
( echo $(( a[0] > 4 )); echo after 4 $?)
# this is a recursion stack error
a=b
b=a
echo $(( a + 7 ))
# make sure command printing works for arithmetic expansions and commands
set -x
var=42
echo $(( $var ))
echo $?
echo $(( $null ))
echo $?
(( $var ))
echo $?
(( $null ))
echo $?
set +x
# invalid expressions in different cases
x=4+
declare -i x
x+=7 y=4
echo x = $x y = $y