concatenate strings in bash
February 12th, 2007 by Lawrence David
let’s say you’ve got:
$j=”foo”
and you’d like to tack on its good partner ‘bar’. then, use the dollar sign and curly braces to delineate variable from string:
$k=”${j}bar”
February 12th, 2007 by Lawrence David
let’s say you’ve got:
$j=”foo”
and you’d like to tack on its good partner ‘bar’. then, use the dollar sign and curly braces to delineate variable from string:
$k=”${j}bar”
Thank a lot
holy crap, thanks a lot man. a search on Google reveals nothing but extremely bad examples and explain nothing.
Bulls eye.. I just got exactly what I needed.
I think it should be like this:
k=“${j}bar”
nice catch ben; duly updated!
Thanks!
thanks!! Very helpful!!
IMHO a simpler solution would be:
#!/bin/bash
j=”foo”
k=”bar”
concatenation=”$j$k”
echo j: $j
echo k: $k
echo j+k: $concatenation
This will produce:
j: foo
k: bar
j+k: foobar
Outstanding!
Just leave out those citation marks…
[jakob@kage ~]$ j=”foo”
[jakob@kage ~]$ k=”bar”
[jakob@kage ~]$ concatenation=”$j$k”
[jakob@kage ~]$ echo $concatenation
””foo””bar””
^^
you don’t get into trouble until you stat with
complicated file names -
PTH=”/work/dir/test”
DTE=”2008/10/31″
FILENAME=${PTH}/${DTE}_suffix.out
this practice guarantees it will work