How to extract value with SOPS without the extra newline in the output?

867 views Asked by At

I'm trying to extract values from a SOPS-encrypted JSON file to export them into environment variables in order to run a web app, but the extraneous newlines keeps driving me crazy.

For example, given this test.json (which is then encrypted with SOPS into test.enc.json),

{
  "password": "the cake is a lie",
  "secret": "shut up about the sun"
}

when I try to extract "password", a newline will be added to the end:

$ sops --extract '["password"]'  --decrypt test.enc.json)

$ echo $password
the cake is a lie

$

Tried trimming the newline with tr -d "\n" and with sed but no joy.

1

There are 1 answers

0
toraritte On

It turns out that what I really needed was --exec-env. From sops --help:

COMMANDS:
     exec-env    execute a command with decrypted
                 values inserted into the environment

When testing it out, it works like a charm:

$ echo $secret

$ sops exec-env test.enc.json bash
bash$ echo $secret
shut up about the sun
bash$
(exit)
$
$ echo $secret

$