Linux 将命令输出放入字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6316822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:27:38 来源:igfitidea点击:
Put command output into string
提问by darko.pp
If I execute some command in a Linux shell, how can I store the output into a string (variable) so I can use it later? I need this for a Bash script, please help.
如果我在 Linux shell 中执行某些命令,如何将输出存储到字符串(变量)中以便以后使用?我需要这个用于 Bash 脚本,请帮忙。
回答by phihag
str=$(command)
回答by Flash
result=`command`
or result=$(command)
both assign the output of command
to the result
variable.
result=`command`
或result=$(command)
同时分配的输出command
到result
变量。