0

I have a bash script which has:

SUCCESS="0"
FAIL="1"
DEBUG="TRUE"

Is it possible to read this in a python script? Something like source.

codec
  • 7,978
  • 26
  • 71
  • 127

1 Answers1

0

A similar question has already been: enter link description here

>>> with open("C:/.../tmp.sh") as f:
        content = f.readlines()
>>> content = [x.strip() for x in content]

Insert into the dictionary and remove quotes if necessary:

>>> import re
>>> divInDict = [{x.split("=")[0]:re.findall(r'"(.*?)"', x.split("=")[1])[0]} for x in content]

Output:

>>> divInDict 
[{'SUCCESS': '0'}, {'FAIL': '1'}, {'DEBUG': 'TRUE'}]

P.S. I only have python 3 so I additionally tested it in python 2 online: enter link description here

George
  • 31
  • 4