0

Hello how can I read a json from filesystem with bash and pass the string as an argument to a python script? I tried this. But it does not work

config=`cat test.json | tr '\n' ' '`
python3 script.py\
    --config $config  \
otto
  • 1,815
  • 7
  • 37
  • 63
  • 1
    Just quote the variable, which you should always do unless you have a good reason not to. – Barmar Oct 01 '20 at 15:00
  • See https://stackoverflow.com/questions/29378566/i-just-assigned-a-variable-but-echo-variable-shows-something-else – Barmar Oct 01 '20 at 15:04

1 Answers1

2

Why eliminate the newlines?

python3 script.py --config "$(<test.json)"

Or if you really need them gone,

python3 script.py --config "$( tr "\n" ' ' < test.json)"
Paul Hodges
  • 13,382
  • 1
  • 17
  • 36