help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] set -u in an arithmetic context


From: Bill Gradwohl
Subject: [Help-bash] set -u in an arithmetic context
Date: Wed, 25 Apr 2012 17:57:47 -0600

#!/bin/bash

declare -a array

set -u

array[2]=5

array[0]=$((array[1]-array[2]))
echo A ${array[0]}

array[3]=$((${array[4]}-${array[5]}))
echo B ${array[3]}

Produces:
address@hidden # ./xxx
A -5
./xxx: line 12: array[4]: unbound variable


Can I conclude that because there is no ${} wrapper around the variables inside the arithmetic context in the first $(()) line that there is no parameter expansion going on and therefore the set -u does nothing?

Is the output intended behavior or should set -u flag the line that works as an error?

How does one get some form of protection during development if set -u doesn't work for the case I showed?

--
Bill Gradwohl


reply via email to

[Prev in Thread] Current Thread [Next in Thread]