Skip to content

Instantly share code, notes, and snippets.

@sandcastle
Created July 1, 2018 08:15
Show Gist options
  • Select an option

  • Save sandcastle/985cc018c707c2a3e0f1191671a80514 to your computer and use it in GitHub Desktop.

Select an option

Save sandcastle/985cc018c707c2a3e0f1191671a80514 to your computer and use it in GitHub Desktop.
Cross platform text replacement recursively in a directory
function text_replace() {
case "${OSTYPE}" in
darwin*) PLATFORM="OSX" ;;
linux*) PLATFORM="LINUX" ;;
bsd*) PLATFORM="BSD" ;;
*) PLATFORM="UNKNOWN" ;;
esac
if [[ "${PLATFORM}" == "OSX" || "${PLATFORM}" == "BSD" ]]; then
find artifacts/ -type f -name "*.yml" -exec sed -i "" "s/$1/$2/g" {} +
else
find artifacts/ -type f -name "*.yml" -exec sed -i "s/$1/$2/g" {} +
fi
}
text_replace "BUILD_TAG" "master-2kl3e7qp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment