Save output in variable?
This question already has an answer here:
您可以执行以下操作: var1=$(ls -l)
I know three ways to do:
1) Functions are suitable for such tasks:
func (){
ls -l
}
Invoke it by saying func
2) Also another suitable solution could be eval:
var="ls -l"
eval $var
3) The third one is using variables directly:
var=$(ls -l)
OR
var=`ls -l`
you can get output of third solution in good way:
echo "$var"
and also in nasty way:
echo $var
链接地址: http://www.djcxy.com/p/57204.html
上一篇: 如何让变量具有当前目录路径?
下一篇: 将输出保存在变量中?