LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 12-06-2008, 06:20 PM   #1
tugce_zehra
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Rep: Reputation: 0
String concatenation problem in a loop


Hello everybody;
I am writing a bash script ,and I need to add substrings in a main string.
Here is the code:

Code:
#!/bin/bash

echo "enter number of columnn in this file"
read NUMBER_OF_COLUMN
MAIN = ""

for (( POS=1 ; POS <= $NUMBER_OF_COLUMN ; POS++ )); do

	echo "enter the name of the column $POS"

	read BUFFER
	MAIN = "$MAIN $BUFFER"
	echo $MAIN
	#temprory line
done

echo $MAIN
Main intention of this code is adding substrings (namely BUFFER) to the main string (namely MAIN).But I had encounter with this error:

code1: line 12: MAIN: command not found

I appreciate to person who solves this.
 
Old 12-06-2008, 06:43 PM   #2
drchuck
Member
 
Registered: May 2007
Posts: 61

Rep: Reputation: 17
Remove the whitespace around the equal signs in lines 5 and 12:
Code:
#!/bin/bash

echo "enter number of columnn in this file"
read NUMBER_OF_COLUMN
MAIN=""

for (( POS=1 ; POS <= $NUMBER_OF_COLUMN ; POS++ )); do

	echo "enter the name of the column $POS"

	read BUFFER
	MAIN="$MAIN $BUFFER"
	echo $MAIN
	#temprory line
done

echo $MAIN
 
  


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
string comparison in for loop harsshal Linux - Software 15 03-04-2008 12:39 AM
Shell string concatenation Quakeboy02 Programming 4 04-26-2007 12:11 PM
string concatenation in c/c++ for a socket program mohtasham1983 Programming 3 02-14-2007 06:42 PM
string concatenation in AWK xanthium Programming 1 04-22-2002 05:41 AM


All times are GMT -5. The time now is 01:30 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration