473,385 Members | 1,912 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,385 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 16968
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.