gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 11:05:37 25 4
gpt4 key购买 nike

我有一些 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

任何的想法?

最佳答案

怎么样:

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

关于shell - 将命令输出重定向到 ksh 中的变量和标准输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7901568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com