I am trying to create a Bash script to download a new file (a Bash script) with various variables and then update OR read one of those variables with one already stored in an existing Python file.
I cannot update the Python file, only read from it.
My Python file (config.py) just contains a list of variables, the one i'm interested in:
iface = 'wlan1'
My Bash script has a variable called IWFace which needs to be the same as iface from the Python file.
#!/bin/bash
IWFACE=wlan1
I have tried all sorts of ways to do this but it seems as I am reading from a Python file it turns out to be really quite difficult.
I have also tried a sed read command to read the variable from the Python file and use it to create a new variable in my Bash script but I'm struggling to make that work.
Is it actually possible? My only other idea was to ask the question via read -p and then store the answer as the variable but as it already exists I wanted to automate the process.
$ifaceis not a valid Python variable name. Without seeing either script, we really cannot offer much by way of guidance. Anyway, this seems like an XY problem. One approach is to write a new Python script whichimports the nasty one and extracts the value of the variable and prints it so that you can retrieve it from your Bash script.iface = wlan0isn't valid Python code unless there's a previously-definedwlan0variable).iface = wlan1without any quotes (that's part of why it's important when showing examples to get the details exactly right). You can find answers that work with the quotes being present in the linked duplicate. (The one I wrote there will work even if the Python script runs some code to dynamically assigniface, though you might get undesired execution if it has module-scoped code without a__name__ == '__main__'guard protecting it).