shell-redirect命令输出到ksh的变量和标准输出

前端之家收集整理的这篇文章主要介绍了shell-redirect命令输出到ksh的变量和标准输出前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些 shell命令.我想将输出写入标准输出并将其保存为变量.
我想用一个命令来解决它.
我试过这些东西
  1. ls > $VAR # redirects the output to file which name is stored in $VAR
  2. ls | tee -a $VAR # writes to standard output as well as in file which name is stored in $VAR
  3. VAR=`ls` # output into $VAR,but it is not sent to standard output
  4. VAR=`ls`;echo $VAR # ok,it works but these are two commands

任何想法?

怎么样:
  1. VAR=$(ls | tee /dev/tty)

猜你在找的Bash相关文章