473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

append a value to an existing variable?

Hi all,
I have a basic shell script question.

Say I have a variable called test.

I already have a value in test = 'monkey'

How do I append another value taken from a file, to this variable?
For example, I wanted to get a value called 'dog' from a file called 'animals', and append dog to the test variable, so that it has the values 'dog monkey' in it.

To make it short :
test = 'monkey'

I wanted to get another value (dog) from a file, and append it to test so I get :

test = 'monkey dog'

Appreciate all your help!

Thanks
Jan 8 '08 #1
2 16969
Expand|Select|Wrap|Line Numbers
  1. $ test=monkey
  2. $ echo dog>file
  3. $ test="$test $(<file)"
  4. $ echo "$test"
  5. monkey dog
  6.  
Jan 8 '08 #2
bykwzpz
13
Hi all,
I have a basic shell script question.

Say I have a variable called test.

I already have a value in test = 'monkey'

How do I append another value taken from a file, to this variable?
For example, I wanted to get a value called 'dog' from a file called 'animals', and append dog to the test variable, so that it has the values 'dog monkey' in it.

To make it short :
test = 'monkey'

I wanted to get another value (dog) from a file, and append it to test so I get :

test = 'monkey dog'

Appreciate all your help!

Thanks

Another way is to simply redefine the variable and include the original like this:

test="monkey" #${test} = monkey
test="${test} dog" #${test} now = "monkey dog"

This would all be done in memory without using the file on disk and be faster.
Jan 29 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: yaffa | last post by:
dear folks, i'm trying to append a semicolon to my addr string and am using the syntax below. for some reason the added on of the ; doesn't work. when i print it out later on it only shows the...
2
by: Nico Grubert | last post by:
Hi there, I would like to open an existing file that contains some lines of text in order to append a new line at the end of the content. My first try was: >>> f = open('/tmp/myfile', 'w')...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
10
by: Rich Wallace | last post by:
I'm sure there's a very weasy way to do this, I've been running hard and fast on several things at once and just may be at the point of overthinking this... I receive an incoming XML document...
2
by: JMCN | last post by:
hi i have a general question regarding append queries in access 97. each week i need to update my table(tblonlinereg) with new or modified records. firstly, i import the text file into my...
2
by: Danny | last post by:
I want to extract a subset of fields from one table into another the master table has many fields the subset has about half, but still many. Is there a way I can just append the master into the...
4
by: azzi2000 | last post by:
I have an existing table, I am trying to update the table. Update existing records with new value and append to it non existing value. Table 1: item, price table 2: item, new price Is there a...
3
by: PseudoMega | last post by:
I'm working with a PHP page I wrote which searches through records in a MySQL database. I have a <form method="post"which currently passes all of search variables into the session array. I'd...
20
by: Pat | last post by:
I know it's not "fair" to compare language features, but it seems to me (a Python newbie) that appending a new key/value to a dict in Python is awfully cumbersome. In Python, this is the best...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.