[BASH] Best way to concat strings

There are many ways to concat strings in bash, but only one is the best. Let’s see the several methods:

x="debian"
y="linux"

z=$x$y		# does work		$z is "debianlinux"
z="$x$y"	# does work		$z is still "debianlinux"
z="$x9 $y"	# does not work		$z is just "linux"
z="${x}9 ${y}"	# does work (best)	$z is "debian9 linux"

So, in our opinion, the best way is the last one, always using the following syntax to get a variable value: ${VARIABLE}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.