将命令输出重定向到ksh中的变量和标准输出

将命令输出重定向到ksh中的变量和标准输出

问题描述:

我有一些shell命令.我想将输出写入标准输出并将其保存到变量中. 我想用一个命令解决它. 我已经尝试过这些东西.

I have some shell command. I would like to write the output to the standard output and save it into variable as well. I'd like to solve it with one command. I have tried these things.

ls > $VAR          # redirects the output to file which name is stored in $VAR
ls | tee -a $VAR   # writes to standard output as well as in file which name is stored in $VAR
VAR=`ls`           # output into $VAR, but it is not sent to standard output
VAR=`ls`;echo $VAR # ok, it works but these are two commands

有什么主意吗?

怎么样:

VAR=$(ls | tee /dev/tty)