This question already has an answer here:
How would I go about saving an output in a vaiable. For example, if I enter:
ls -l
it will show the files. How would I go about saving the output in a variable? Is it possible at all?
This question already has an answer here:
How would I go about saving an output in a vaiable. For example, if I enter:
ls -l
it will show the files. How would I go about saving the output in a variable? Is it possible at all?
You can do the following:
var1=$(ls -l)
I know three ways to do:
1) Functions are suitable for such tasks:
Invoke it by saying
func
2) Also another suitable solution could be eval:
3) The third one is using variables directly:
you can get output of third solution in good way:
and also in nasty way: