将命令输出重定向到ksh中的变量和标准输出 [英] redirect command output into variable and standard output in ksh

查看:84
本文介绍了将命令输出重定向到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆