strcat equivalent in shell scripting

Hi all,
How does string concatenation work in shell scripting?

I basically have a variable called "string" and I want to add the strings "aaa" "bbb" "ccc" "ddd" to the variable "string". These strings would be added based on some conditions and separated by spaces . So "string" might look like
string = aaa bbb ccc

Any ideas? Thanks.

You can use like -

String="$a $b $c"

where a="aaa"
b="bbb"
c="ccc"

STRING1=my
STRING2=string
STRING3="$STRING1 $STRING2"
echo $STRING3
> my string

Thanks guys, but lets assume that I have a really long list, in which case I cannot be assigning variables for all these data values.

An example would help - a sample input and a desired output as always!

Vgersh is very good at this type of problem and I don't want to but in, but most cases, in most shells, using an array to store the data and exploding the array is a simple way to form a concatenated string of disparate variables.

Short example with bash and gawk.

function retrandstr() {
gawk '
  function retrandchars(str, sz,rval,i) {
  sz = int(1 + rand() * length(str))
  i =0
        #print sz, i; 
         while (i < sz) {
                rval = rval substr(str,int((1 + rand() * length(str))),1); 
                i++;
          }
  return rval
  }
  BEGIN {
    srand();
    print retrandchars("abndhcv784893ndyvurfgh3ery348infy7478")
  }'
  sleep 1
}

Test--
while test "$i" -gt 0;  do arr[$i]=`retrandstr`; i=`expr $i - 1`;  done
list=${arr[@]}

Vgersh, I have posted a sample in comment #1.
The only thing is that data values will be added to the "string" variable based on a condition. So for example string = aaa ccc ddd.

For example in the first loop "string" would contain no data then based on a condition "aaa" will be added to it. In the next loop if the condition satisfies "ccc" will be added, but "string" should contain "aaa" as well, so the end value would be "aaa ccc". Hope this helps.

You can do that by using this general construct:

string="$string <value to be concatenated to string>"

And you can keep doing this for as many concatenations as you like.

> cat file1
#!/usr/bin/ksh
string="A string"
string="$string has been lengthened"
echo $string

> ./file1
A string has been lengthened
>

It doesn't matter whether you use literal strings or variables, you concatenate them in the same way:

string="$a $b $c ..."
string="one two three four ..."

If you want to store the conents of a file in a variable:

string=$( cat "$FILENAME" )