How can I change the values of Python variables using bash? -


i writing bash script automates installation process on linux. @ 1 point, need go inside python file used configuration file application being installed , change values of 2 specific variables new values. in other words, suppose have .py file contains (note: "apple" , "orange" may change):

# code here = "apple" b = "orange" # rest of file 

and need change values specifically "banana" , "pear":

# code here = "banana" b = "pear" # rest of file 

how can automate change using bash?

as unwind says, if can modify python script, accept values parameters. however, can't that, because script provided external package. sed's in-place search , replace looks this:

sed -i 's/a = "apple"/a = "banana"/' filename     

using bash variables, have use "" sed, otherwise shell won't expand variables. means have escape literal " marks, making less clear read:

export testvar="banana" sed -i "s/a = \"apple\"/a = \"$testvar\"/" filename 

to swap them no matter in original:

sed -i 's/a = ".*"/a = "banana"/' filename 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -