Getting size of a variable

if i do the following:

echo "hello, mr. sunshine" > /tmp/text.txt

du -s /tmp/text.txt

The text.txt file now contains "hello, mr. sunshine". So i did a du -s on the file to see how much space the text i inserted took.

now, instead of writing "hello, mr. sunshine" to a text file on the disk, i'd like to save it to a variable and calculate how much space it would take on disk without having to write to disk.

So, something along the lines of:

VAR="hello, mr. sunshine"

du -s $VAR  (this wont work of course, since the content of a $VAR is not a actual file).

Is what i'm asking possible?

I'm running Red Hat 6 and Sun 5.10 and i'm using bash.

Could this help you ?

echo ${#VAR}   #display length of variable VAR

it could actually. i guess the next question would be, how many character makes up 1K?

What about a

wc -c

command?
Seems strange the writing to a file to determine how big. Why not simply the word-count command?

what i'm looking for is how much disk space would be consumed if what i have in variable was written to disk

Well, that is a function of how much stuff is there. The wc command can give an indication of how large; for an exact answer you would need to know more about your disk system -- 512 byte blocks, 1024 byte blocks, etc...