Redirecting output to a variable?
It seems quite straightforward.
romano@RRyS:~$ size=$(ls -l /var/spool | wc -c)
romano@RRyS:~$ echo $size
476
The shell syntax $(command)
executes command
, and returns the standard output: just save it in a variable.
Your command:
ls -l /var/spool | wc -c > size
will create a file named size
in the current directory (containing the number and a newline).
I prefer the solution offered by Rmano's answer, but if you want to use only redirection:
read size < <(ls -l /var/spool | wc -c)