LinuxQuestions.org
Review your favorite Linux distribution.
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, 09:16 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Rep: Reputation: 51
Variable concatenation in bash.


Hi:

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

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


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

Original Poster
Rep: Reputation: 51
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, 01:22 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:29 PM
-bash: HISTSIZE: readonly variable -bash: HISTFILESIZE: readonly variable deathsfriend99 Linux - Newbie 4 12-08-2009 01:51 PM
How to get variable from text file into Bash variable mcdef Linux - Software 2 06-10-2009 02:15 PM
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 04:08 AM
Bash Concatenation alieas Programming 3 09-04-2006 02:45 PM


All times are GMT -5. The time now is 06:40 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration