将命令输出重定向到 ksh 中的变量和标准输出 [英] redirect command output into variable and standard output in 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)
这篇关于将命令输出重定向到 ksh 中的变量和标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文