Skip to content

Instantly share code, notes, and snippets.

@davetapley
Last active August 29, 2015 14:27
Show Gist options
  • Save davetapley/2de1c6a93548bcaffd8a to your computer and use it in GitHub Desktop.
Save davetapley/2de1c6a93548bcaffd8a to your computer and use it in GitHub Desktop.
Substring Replacement in Bash
# Works okay:
FILE=something.txt; echo ${FILE/txt/log}
# Works okay:
find . -name \*.txt -exec sh -c 'FILE={}; echo ${FILE}' \;
# Fails with 'sh: 1: Bad substitution':
find . -name \*.txt -exec sh -c 'FILE={}; echo ${FILE/txt/log}' \;
# Works
find . -name \*.txt -exec bash -c 'FILE={}; echo ${FILE/txt/log}' \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment