【问题标题】:How to fetch output of command into a variable? [duplicate]如何将命令的输出获取到变量中? [复制]
【发布时间】:2020-05-12 17:14:37
【问题描述】:

我正在尝试运行命令并将值存储在列表中

list = `sed -n 's/^abc//p' /etc/filename`

我在运行上述命令时收到错误command not found

但是,当我直接运行sed -n 's/^abc//p' /etc/filename 命令时,输出如下:

abc01 abc02 abc03

【问题讨论】:

  • 删除=list=$(sed -n 's/^abc//p' /etc/filename)周围的空格

标签: linux bash shell sed rhel


【解决方案1】:

使用

list="$(sed -n 's/^abc//p' /etc/filename)"

变量声明和等号后不能有空格。此外,引用变量也很重要。

【讨论】:

  • 引用确实是一种很好的做法,但在目前的情况下,它是不需要的。
猜你喜欢
  • 2012-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-26
  • 1970-01-01
  • 2014-10-21
  • 2011-01-19
  • 1970-01-01
相关资源
最近更新 更多