The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Concatenate the string with the newline character youareapkman Shell Programming and Scripting 3 09-16-2008 10:23 AM
Concatenate String through Awk monu_munish Shell Programming and Scripting 3 04-18-2007 04:17 AM
How to concatenate two strings or several strings into one string in B-shell? fontana Shell Programming and Scripting 2 08-26-2005 12:58 PM
how to cut a string from a variable kjaisan UNIX for Dummies Questions & Answers 2 10-30-2003 01:13 PM
Asking on concatenate variable blueberry80 UNIX for Dummies Questions & Answers 3 07-25-2003 10:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-24-2008
sreedivia sreedivia is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 5
How to concatenate a string and a variable

I need a way to build variable in this manner:

variable_$i
Inside a for loop i need to create it.
where i goes from 1 to 30..
and then i need to print them on screen with echo $variable_$i
which is the best way to do this?
  #2 (permalink)  
Old 10-24-2008
togr togr is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 37
echo ${variable}_${i}

curly braces are used to emphesize the actual name of the variable, usually it's not necessary but sometimes a bit confusing constructions are used,
  #3 (permalink)  
Old 10-24-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,350
An example:


Code:
#!/bin/sh

variable=AA
i=1

while [ i -le 30 ]; do
  echo ${variable}_${i}
  let i=i+1
done

Regards
  #4 (permalink)  
Old 10-24-2008
sreedivia sreedivia is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 5
Thanks for your reply.
How can i assign a value to this variable
${variable}_${i}="somestring" is it work?
  #5 (permalink)  
Old 10-24-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 3,020
thread moved to "Shell Programming and Scripting". please watch out to post in the right sub forum!
  #6 (permalink)  
Old 10-24-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,350
Quote:
Originally Posted by sreedivia View Post
Thanks for your reply.
How can i assign a value to this variable
${variable}_${i}="somestring" is it work?
The way to learn scripting/programming or whatever is to do it yourself, just try it out......

Regards
  #7 (permalink)  
Old 10-26-2008
togr togr is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 37
Quote:
Originally Posted by sreedivia View Post
Thanks for your reply.
How can i assign a value to this variable
${variable}_${i}="somestring" is it work?
this is not a one single variables. these are two distinct variables.
Closed Thread

Bookmarks

Tags
concatenate variable

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0