Appending data into a variable

Hi,

I would like to know if it's possible to append data into a variable, rather than into a file. Although I can write information into a temporary file in /tmp, I'd rather if possible write into a variable, as I don't like the idea that should my script fail, I'll be polluting the server with messy temp files. Currently my script has a for loop containing:

echo "$line" >> $tmpdir

where $tmpdir represents a filename. Is there a way round this?

str="${str}
${line}"

you could use the read statement:

echo "HELLO" |read hello
echo $hello

Note: read command Reads one line only from standard input

That will fail in most shells, because each element of a pipeline is executed in a subshell.

If all you are doing is echoing a value, just assign the value to a variable instead:

var=$line

If it's a real command, use command substitution, e.g.:

var=$( ls -l "$FILE" )

you can var=`echo "$var $tmpdir"` in the loop