Skip to content

Instantly share code, notes, and snippets.

@jeffmccune
Created October 24, 2011 21:29
Show Gist options
  • Save jeffmccune/1310371 to your computer and use it in GitHub Desktop.
Save jeffmccune/1310371 to your computer and use it in GitHub Desktop.
Incrementing environment variables

The test Script

#! /bin/bash
set -x
set -e
set -u
idx=0
((idx++))
echo "rval: $?"
echo "idx: $idx"

On CentOS 5.5

root@pe-centos5:/vagrant/bin# ./test 
+ set -e
+ set -u
+ idx=0
+ (( idx++ ))
+ echo 'rval: 1'
rval: 1
+ echo 'idx: 1'
idx: 1

On Lucid

root@pe-ubuntu-lucid:/vagrant/bin# ./test ; echo $?
+ set -e
+ set -u
+ idx=0
+ (( idx++ ))
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment