-   Linux - Newbie (
-   -   Bash scripting, separating variable from string text (

emmalg 06-25-2009 01:27 PM

Bash scripting, separating variable from string text
Hi All

I remember there is a whay to do this with brackets, but I can't remember exactly how and can't come up with the right search term to google it!

I have:


I want to get:




wont work as it alays thinks the underscore is part of the variable name.

Whatever I do, it has to print correctly with echo and most importantly be correctly passed to another shell command I'm trying to execute.


David the H. 06-25-2009 01:59 PM

The long form of the variable is ${var}.


There's a handy reference page of bash commands at the ABSG here.

You can also escape or quote parts of the string that you want to be seen as literal. The following will all work:


Edit after testing: Except that they don't always not work when surrounded by other quotes in an echo command. For that, try echo "$foo"_"$bar".

druuna 06-25-2009 01:59 PM


Use curly brackets:


Hope this helps.

emmalg 06-26-2009 04:31 AM

Thank you both very much!!

Sometimes there's too much information on the internet to find what you need! It's really good to have a forum like this at those times!


All times are GMT -5. The time now is 04:47 PM.