OSX sed: Match Bash Variable, and then Delete or Append Bash Variable

Bash: GNU bash, version 4.3.33(1)-release (x86_64-apple-darwin14.1.0)

Working with Neo4j, I wanted to simplify turning on/ off debugging via the Neo4j properties file, so I decided to use sed to do this. This code is just the sed lines to do this.

This has the infamous OS X -i ‘’ argument to do the substitution in place.

# This is the line I either want - to don’t want - in my neo4j-wrapper.conf file:
DEBUG_CONFIG="wrapper.java.additional=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y"

sed -i '' "/\(^${DEBUG_CONFIG}$\)"'/d' ./neo4j-wrapper.conf

# This is the line after which I will add my debug config line

# After the match line, append the Debug configuration.
sed -i '' "/\(^${MATCH_LINE}$\)"'/a\'$'\n'"${DEBUG_CONFIG}"  ./neo4j-wrapper.conf

Thanks to jw013’s answer at http://unix.stackexchange.com/a/52141/118244 I was able to sort out the $’\n’ syntax to encourage bash to pass the newline to sed.

See also: http://unix.stackexchange.com/questions/52131/sed-on-osx-insert-at-a-certain-line

Bash 4.x Script to Show/ Hide Hidden Files in OSX

Tested on Yosemite with bash 4.3.33 (which was installed via homebrew, (http://johndjameson.com/blog/updating-your-shell-with-homebrew/).

#!/usr/bin/env bash
# A Bash 4.x Script to Show Hidden Files in OSX
function show_help() {
    >&2 echo "Please specify what I should do with hidden files:"
    >&2 echo -e "\tyes (show)"
    >&2 echo -e "\tno (don't show)"

if [[ $# < 1 ]] ; then
    exit 1
echo $yes_or_no
if [[ "${yes_or_no}" != @(YES|NO) ]]; then
    >&2 echo "Invalid argument '$1'"
    exit 2
defaults write com.apple.finder AppleShowAllFiles $yes_or_no
killall Finder