LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-09-2010, 08:16 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
Variable concatenation in bash.


Hi:

How do I concatenate two environment variables in bash? Thanks.
 
Old 11-09-2010, 08:21 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
var3=${var1}${var2}
?


Cheers,
Tink
 
1 members found this post helpful.
Old 11-10-2010, 07:02 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thanks, Tink, for your kind reply and excuse my laziness in not having consulted any elementary shell script tutor. I must have begun studying shell scripting a hundred times but never got far.
 
Old 11-11-2010, 12:22 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by Tinkster View Post
Code:
var3=${var1}${var2}
?
That is never wrong but the { } is only necessary when the character after the variable name is a valid name character. According to the DEFINITIONS section of the bash man page, a name is "A word consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore". That does not include $ so variables can be concatenated by $var1$var2$var3 (providing that whatever follows var3 is not an alphanumeric character or underscore).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: How do I read data from a variable while that variable is being populated? theaceoffire Programming 4 04-23-2010 02:29 PM
-bash: HISTSIZE: readonly variable -bash: HISTFILESIZE: readonly variable deathsfriend99 Linux - Newbie 4 12-08-2009 12:51 PM
How to get variable from text file into Bash variable mcdef Linux - Software 2 06-10-2009 01:15 PM
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 03:08 AM
Bash Concatenation alieas Programming 3 09-04-2006 01:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration