在 bash 中执行命令的响应

Execute a Response of a command in bash

在下面的脚本中,sed 的响应是

export SECRET_KEY= '321321

我需要在 shell 中执行该响应,将值导出到 SECRET_KEY 即 echo $SECRET_KEY 会将导出的密钥作为 321321

aws-runas test >>test.txt
echo `sed -n -e 's/^.*\(\(export SECRET_KEY\).*\)//p' test.txt`

我试过使用 evalsource <(echo $command)。它给出了以下错误

sed: -e expression #1, char 13: unterminated `s' command

有没有办法将sed的响应作为命令执行?

你可以只使用 sed:

`sed -n -e 's/^.*\(\(export SECRET_KEY\).*\)//p' test.txt`

小心,您所做的导出不起作用。

export SECRET_KEY= '321321'
export: not an identifier: 321321

使用:

export SECRET_KEY=321321