Bash Tip – Separate a Bash Variable From Surrounding Letters

Sometimes, you might find yourself needing to concatenate the value of a bash variable with a string.
I think it’s best demonstrated with (a somewhat artificial) example:

1
2
3
y=h
echo $yome #won't work. will print the value of the variable "yome" which is a null string (since it's not set)
echo ${y}ome #works. will print "home"

That’s it, the trick is to use the curly brackets ${var} to separate the variable from its surrounding.

Have fun ;-)

source: @bashcookbook

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Related posts:

  1. Fetch Links From Twitter Into Your RSS Reader
  2. Google Reader Useful “Send To” Services
  3. Regular Expression To Check For Prime Numbers
  4. Vim Tip – Convert Code To HTML
  5. Make Google Even Smarter With Google Subscribed Links

Tags: ,

Saturday, April 24th, 2010 Bash

Leave a Reply

my email
my photo
Hi,
My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
I'm a Verification Engineer in Mellanox Technologies Ltd.
I love Linux, the Command Line and the OpenSource Community.
I used to write Poems (Arabic) when I was able to find time for this.
April 2010
S M T W T F S
« Mar   May »
 123
45678910
11121314151617
18192021222324
252627282930  
SEO Powered by Platinum SEO from Techblissonline

Twitter links powered by Tweet This v1.7.3, a WordPress plugin for Twitter.