I am trying to set a global/system variable in my computer, I am using Yosemite.
I opened my ~/.profile (that is the default profile file configuration) , and I added this
setenv var.Property someValue
but it didnt work,
Neither this way
export var.Property = someValue
everytime I do echo $var.Property I get as result "Property" I think the "." may be interfering with this. I do need to have it this format, but unfortunately, is not working.
Any idea how to do this?
You will get a different environment based on if you start via command line vs double clicking ... if you start with the command line you should get whatever is in env and if you start by clicking it then you will get whatever is in launchtl's env... so for that to change you use
launchctl setenv DOG cat
Edit:
it seems as though you can't have an env var with a key that has a period in it... this works fine in csh:
setenv var.Property someValue
Related
In Windows' Environment Variable Tab, the User Variable and System Variables are separated. I have a MacBook Pro and would like to add new 'user' variables like Windows. Is this possible? I mean I found there are temporary variables that can be created in the Terminal, but if that Terminal is closed, the variables are gone. I found a way to do a permanent variable, but do not want to mess things up in the core of the macOS. Are there any recommendations?
If you set variables in the ~/.bash_profile file, they will always exist since this file is automatically run every time you open Terminal.
To edit it:
vim .bash_profile
(i to insert text, esc to exit insert mode, :q! to discard and quit, :x to save and quit)
Then add:
export VARIABLE_NAME=value
Save and quit the editor (:x). Then to check if it worked:
echo $VARIABLE_NAME
When the terminal is bash, editing the .bash_profile works.
If you're using zsh, then edit
~/.zsh and add the command as
""export variableName = value"" in to the file
Now, run
""source ~/.zsh""
OSX Catalina & zsh as my terminal.
I have a command to start a psql connection :
db, err := pgx.Connect(context.Background(), os.Getenv("PSQL_URL"))
But the os.Getenv("PSQL_URL") is an empty string.
How to make sure go program can read my environment variable ?
In the terminal, if I echo $PSQL_URL I get the proper postgresql://aod:toto#localhost/dbname
If I export PSQL_URL="postgresql://aod:toto#localhost/dbname" before running main.go it works fine
I'm looking for a persistent way of doing it.
UPDATE
My mistake was as follow :
Inside ~/.zhsrc I did set
PSQL_URL="postgresql://aod:toto#localhost
instead of
export PSQL_URL="postgresql://aod:toto#localhost"
That's the correct way of reading an env variable in go.
The only thing that comes to my mind about what might be happening is that you have two different terminal sessions. In one of them you set PSQL_URL (you are running the echo in this one) and in the other not (you are running your go app here).
EDIT
Expanded now with the your comments and Felix's, the problem here is that you export a variable, but don't make it permanent, so when you start a new session the variable doesn't exist. What you need to do is edit your ~/.zshrc and add export PSQL_URL=foo, this way, whenever you start a new terminal session, the variable will be loaded.
I have a requirement where I need to set a custom environment variable called CLUSTER_ENV = '#fooURL'
The steps I have followed are:
Open terminal, open bash_profile and save CLUSTER_ENV='#foo'. When I do echo $CLUSTER_ENV , I get blank output.
I did the same thing in the bashrc file and in this case, the $CLUSTER_ENV shows the value only when I run it in the same terminal window.
Which is the best or recommended way to permanently set the environment variable on a Mac?
Im running El Capitan.
I have gone through these links for reference:
http://osxdaily.com/2015/07/28/set-enviornment-variables-mac-os-x/
Mac OS X 10.9 - setting permanent environment variables
As you will normally do on any Linux distro: export CLUSTER_ENV=my.url.com which will have to be added to ~/.bash_profile
I have wasted most of the day trying to get some simple environment variables set that will be visible to GUI apps along with shell variables. I have tried virtually everything I've found on the web, but I can get a variable set with launchctl to visible in bash. I have a script that runs as a login item that does a simple launchctl setenv FOO BAR. When I type launchctl getenv FOO it returns BAR. If I type echo $FOO I get an empty string. I can't believe apple would something this simple so hard. I must be missing something. Am I?
When you type launchctl setenv FOO BAR in Terminal you are setting the variable in launchd environment. You will have to restart Terminal (all its processes) to see the change. launchd will pass your new variable while starting Terminal and it will be visible in it's new instance running echo $FOO. The same applies to all applications.
I am trying to download myrna tool on mac os x.
for one of procedures on installation, "Set the MYRNA_HOME environment variable to point to the extracted directory (containing myrna_emr)"
So i tried this way
echo "export MYRNA_HOME=/.../....directory/.." >> ~/.bashrc
but it seems it does not work.(when i type echo MYRNA_HOME in command line, there is nothing OR when i type printenv MYRNA_HOME does not come out.)
anyone who knows how to set up Env Vars??
thank you,
There are several ways to do that. One would be adding your variable to ~/.bash_profile file.
Example:
MYRNA_HOME=/whatever/you/want/
export MYRNA_HOME
Then you can try if it works by logging in again and trying on a terminal:
$ echo $MYRNA_HOME
It should print whatever you set MRYNA_HOME to on ~/.bash_profile.
If you want the environment variable to be available to all users, you can change /etc/bashrc file. But I would prefer just changing one users' environment.