Skip to content

Instantly share code, notes, and snippets.

@jessitron
Created June 16, 2024 20:16
Show Gist options
  • Save jessitron/ebfd8bd3bc488c0ca367dacd641a5654 to your computer and use it in GitHub Desktop.
Save jessitron/ebfd8bd3bc488c0ca367dacd641a5654 to your computer and use it in GitHub Desktop.
updating the version number after the deploy, by editing the deploy script
#!/bin/sh
# do something with a version number, and then increment the version number in this script.
# Is this a good idea? No claims made.
set -e # exit on fail
set -x # print what you're doing
me=$0 # name of this script
VERSION_NUMBER=5
## Do stuff with the version number
echo "I am $me, with version number $VERSION_NUMBER"
## Now change this script to increment the version number, so next time it will be different.
function sed_in_place {
expr=$1
file=$2
backup=$file.bak
sed "$expr" $file > $file.bak
chmod `stat -f %A $file` $file.bak # this works on mac, to copy file permissions.
mv $file.bak $file
}
sed_in_place "s/VERSION_NUMBER=$VERSION_NUMBER/VERSION_NUMBER=$(( VERSION_NUMBER + 1 ))/" $me
@reitzig
Copy link

reitzig commented Jun 16, 2024

Came here from your blog to ask: Is there a particular reason against using sed --in-place? 🤔

@jessitron
Copy link
Author

wouldn't that be lovely? 😢
The version of sed on my mac doesn't have it. Same with chmod --reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment