Skip to content

Instantly share code, notes, and snippets.

@martynjarvis
Created January 26, 2015 15:05
Show Gist options
  • Save martynjarvis/9f57a495fa86e0820d69 to your computer and use it in GitHub Desktop.
Save martynjarvis/9f57a495fa86e0820d69 to your computer and use it in GitHub Desktop.
Automatically incrementing run number in bash script
#!/bin/bash
# counter for current run number
if [ ! -e "${HOME}/.counter" ]
then
echo "creating counter file"
echo "1" > ~/.counter
fi
while read line
do
runNo=$line
done < ~/.counter
# Now do stuff with $runNo
echo $runNo
# update counter
let "runNo += 1"
echo "$runNo" > ~/.counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment