I have created a .bashrc
file using:
touch ~/.bashrc
and I am trying to get all the variables in it to be environment variables in my current environment. I saw online that you can source into it as source ~/.bashrc
but nothing changed when I did this (I could not access the variables), however I could run cat ~/.bashrc
and still see the variable names as the key and the variables as the password.
I tried to also loop through it as
import os
# open the .bashrc file in the home directory (~/)
with open('~/.bashrc') as f:
# read the lines in the file
lines = f.readlines()
# iterate over the lines in the file
for line in lines:
# split the line into parts
parts = line.split('=')
# if the line has the correct format (key=value)
if len(parts) == 2:
# extract the key and value
key, value = parts
# remove any leading or trailing whitespace from the key and value
key = key.strip()
value = value.strip()
# set the key as an environment variable with the corresponding value
os.environ[key] = value
but the open did not run, giving the error.
FileNotFoundError: [Errno 2] No such file or directory: '~/.bashrc'
How can I import all the variables in my .bashrc
file ?