Unix command to concatenate (attach) two strings?

Showing Answers 1 - 7 of 7 Answers

Madhuker Sinha

  • Jul 20th, 2006
 

For concatenating two string we use cat command.

Ex:- cat str1 str2

  Was this answer useful?  Yes

Mukund

  • Aug 1st, 2006
 

echo $var1 $var2

  Was this answer useful?  Yes

Asha Sonani

  • Aug 25th, 2006
 

var1=$var1$var2

echo $var1

  Was this answer useful?  Yes

Ramya Murthy

  • Nov 2nd, 2006
 

you can concatenate two strings by using the echop command..echo -e -n str1; echo str2 | cat

  Was this answer useful?  Yes

Markerhell

  • Aug 26th, 2009
 

There are two different ways to do the same.

1.
var1 = "first"
var2 = "second"
var3 = $var1$var2

The only problem with the above solution is you can not attach the general text at hte end or in between of the text to create new string as variable which is not present so it will give an error.

BEST SOLUTION IS:

2.
var1 = "first"
var2 = "second"
var3 = ${var1}$var2

This will also work. In addtion to this, if you want to add some general text, you can add.
ex. var3 = $var1${var2}thisistestadddition
the var3 will be firstsecondthisistestadddition

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions