|
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!!
|