increment the number in a file

Lets say you have a file called REVISION which contains a single number. If you want to increment the number in that file you could run the following command:

let rev=`cat REVISION`+1 && echo $rev > REVISION

Wrap that up as a nice shell script and you get a nice increment command:

#!/bin/bash
let rev=`cat $1`+1 && echo $rev > $1


[nathan@nate ~]$ cat REVISION
1
[nathan@nate ~]$ increment REVISION
[nathan@nate ~]$ cat REVISION
2

Share:
  • del.icio.us
  • Reddit
  • Technorati
  • Twitter
  • Facebook
  • Google Bookmarks
  • HackerNews
  • PDF
  • RSS
This entry was posted in sysadmin. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.