0

In the following script the response of sed is

export SECRET_KEY= '321321

I need to execute that response in the shell, exporting the value to SECRET_KEY i.e. echo $SECRET_KEY will give the exported key as 321321

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

I've tried using eval, source <(echo $command). it gives the following error

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

Is there a way to execute the response of sed as a command?

Kaveen M.
  • 115
  • 9

1 Answers1

1

You can just use sed:

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

Be careful, the export that you made doesn't work.

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

Use:

export SECRET_KEY=321321
  • I'd recommend using `$( )` instead of backticks -- escaping in backticks is a bit weird, and while this particular command happens not to trigger any of the weirdness, it's best to just avoid backticks altogether. See [BashFAQ #82](http://mywiki.wooledge.org/BashFAQ/082) and [this question](https://stackoverflow.com/questions/9449778/what-is-the-benefit-of-using-instead-of-backticks-in-shell-scripts). – Gordon Davisson Feb 13 '22 at 19:11