The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 06-26-2006
oma04 oma04 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 3
Assigning output of command to a variable

Hi,

I'm trying to assign the output of a command to a variable and then concat it with another string, however, it keeps overwriting the original string instead of adding on to the end of the string.

Contents of test.txt --> This is a test

var1="`head -n 1 test.txt`"
echo $var1 (This is a test)

var1=$var1"123"
echo $var1 (123s is a test [instead of: This is a test123)

The issue has something to do with the first line. If I simply assign a string like this:
var1="This is a test" , then it all works, but when I try to assign the output of a command to a variable, it does not add to the string properly.

Does anyone know how to get around this??

Thanks!!