Another tip when using quotation marks

There's one final thing that we want to talk about. If you want to store the output of the command:

ls -al 
            

Set it to a variable value "files":

files=`ls -al`	
            

This then assigns the output of the ls -al to a variable called files. If you now type:

echo $files
            

You would see that this appears to have written all those files, plus all their permissions, everything on a single line.

Well that is not really what echo is doing, all that it has done is not to honour the newline characters. We need to find a combination in our command that assures our results are also formatted correctly and the only way we can preserve the formatting is to use double quotes. Thus if you type:

echo  "$files"
            

you would get back your listing the way you expect, the newline characters would be preserved. This can be quite useful.

For example:

diskfree=$(df -h)
echo $diskfree
            

will give you one lone line with all that disk information in it.

Typing:

echo "$diskfree"
            

will ensure that you see what you expect: a tabular format rather than a long line format.