55

How can I concat strings in shell? Is it just...

var = 'my';
var .= 'string';

?

1
  • 5
    FYI variables in bash can't have spaces around the =. It has to be next to the name and the value. Commented Feb 25, 2012 at 16:10

3 Answers 3

89

How about this:

var="${var}string"
Sign up to request clarification or add additional context in comments.

Comments

30

It depends on the shell, but since question was tagged bash:

var='my'
var=$var'string'

Comments

11

No. For various reasons.

# most sh-compatible shells
var="my"
var="$var string"

# advanced shells
var="my"
var+=" string"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.