Posted by: terryhowe | September 29, 2016

Bash Environment Variable Search and Replace

I was trying to modify a bash environment variable today and traditionally how you did that was with command substitution and sed or awk.  Something like:

OS_TENANT_NAME=`echo $OS_TENANT_NAME | sed -e s/mesos/admin/g`

 

I had to throw in the accent grave there to make it super old school.

Anyway, I’m doing this and thinking that by now there has to be a better way to do this and bash does support search and replace in variables now:

$ echo ${OS_TENANT_NAME}
dev-mesos
$ OS_TENANT_NAME=${OS_TENANT_NAME/mesos/admin}
$ echo ${OS_TENANT_NAME}
dev-admin


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: