How to concat variable and string in bash script How to concat variable and string in bash script bash bash

How to concat variable and string in bash script


Strings are concatenated by default in the shell.

value="$variable"text"$other_variable"

It's generally considered good practice to wrap variable expansions in double quotes.

You can also do this:

value="${variable}text${other_variable}"

The curly braces are useful when dealing with a mixture of variable names and strings.

Note that there should be no spaces around the = in an assignment.


Nice.

Mac OS X 10.12 works with following ...


#!/bin/bashvar1=barvar2=foovar3="$var1"sometextecho $var3

Result

= barfoosometext


Late for the party, my 2 cents for another solu., also works in zsh:

i=`date +%d%b`

val1="$i-i-*"