我有一些Shell命令。我想将输出写入标准输出并将其保存到变量中。 我希望只用一个命令解决这个问题。 我已经尝试了以下方法。
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
有什么想法吗?