Thursday 2 November 2017

shell - How to concatenate string variables in Bash

itemprop="text">

In PHP, strings are concatenated
together as follows:



$foo =
"Hello";
$foo .= "
World";



Here,
$foo becomes "Hello
World".



How is this accomplished in
Bash?



Answer




foo="Hello"
foo="${foo}
World"
echo "${foo}"
> Hello
World



In
general to concatenate two variables you can just write them one after
another:



a='Hello'
b='World'
c="${a}
${b}"
echo "${c}"
> Hello
World

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...