I'm having a hard time trying to get multiple environment variables configured at the same time. Here are some issues that I would like answered:
If I do have spaces in my PATH environment variable (i.e. C:\Program Files\Java\jdk1.6.0_25), is there any way to keep the same path, but make sure that nothing unexpected happens? I keep hearing that you shouldn't use spaces like in this link here: http://ist.berkeley.edu/as-ag/technology/howto/install-java-sdk-win.html.
Is there a difference in the ordering of the environment variables as listed in the fields?
What will happen if environment variables in the "User variables for user" fields and the "System variable" fields are different? Is it safe to assume that the result will be all the fields combined for that particular variable?
Thanks for any advice!
Related
While working on my project at work, I came across a startup script for the application which just kind of sets up all the environment variable, paths that sort of thing. I see variables assigned to values like this
set abc=%def%
and also like this:
set xyz=#pqr#
Whats the difference between using #xxxx# against %xxxx% ? I haven't done any batch scripting but looked around could not find an answer to this strangely.
% marks things as variables, which you can set, change, and read, (You can also use ! if delayed expansion is enabled.) while # is just a character, which will print as is and is not used for variables.
my .bash_profile looks this way :
When I open my terminal I get this three lines :
-bash: export: Workbooks.app/Contents/SharedSupport/path-bin': not a valid identifier
-bash: export:Workbooks.app/Contents/SharedSupport/path-bin': not a valid identifier
-bash: export: Workbooks.app/Contents/SharedSupport/path-bin': not a valid identifier
-bash: export:Workbooks.app/Contents/SharedSupport/path-bin': not a valid identifier
What should I remove from my .bash_profile to get rid of this ?
There are multiple errors here, but the one you are asking about is because the space in Xamarin Workbooks needs to be escaped or quoted. See also When to wrap quotes around a shell variable?
The repeated fragments are certainly erroneous as well; the repeated code should only be present once. I'm guessing you ran some buggy installer multiple times, and it blindly added stuff which contained errors in the first place, and definitely should not be added again if it was already present. If you can identify this installer, maybe submit a bug report to its maintainer.
Hardcoding a complex PATH is also usually wrong. Generally, the correct behavior is to preserve your previous PATH, and only add a single additional directory before or after the old value, like
PATH=/new/stuff:$PATH
or
PATH=$PATH:/new/stuff
where /new/stuff is the added directory, and $PATH recalls the variable's previous value.
If something blindly overrides your locale settings programmatically, that's also a bug, and outright hostile if your real locale settings were correct and useful. Using LC_ALL is quite likely severe overkill in any event; if a particular application requires you to override a particular locale setting, it should only override the specific one(s) it needs, not everything. But really, even then, it has no business writing this stuff to your personal preferences.
The Conda fragment also contains an example of poor practice (some would call it an antipattern); see also Why is testing "$?" to see if a command succeeded or not, an anti-pattern?
export PATH should not be necessary at all, though specifying it needlessly is harmless per se, and removes the assumption that the shell's system-wide startup files have already exported it. Exporting the same variable multiple times in the same script is just silly, though.
I like to modify my Windows environmental variables by opening the Advanced System Settings -> Environmental Variables. I particularly like that when I try to modify the system path (by clicking on System Variables -> Path), that I get a nice, easy to read list of the folders on the path:
However, when I click on the User Variables -> Path, I still get the old dialog, which is not very user friendly:
Is it possible to have Windows always display the list, as is the case for the System variables?
For what its worth, I think I remember seeing the desired behavior on a friend's computer, so I believe it should be possible.
EDIT:
It seems that having a variable as part of the path is the problem. Is there a way to get path list even when the path contains variables?
Context:
When I want to add a program to my path, I will create a new variable that redirects to its path. The reason to do that is simple... Programs typically have compound paths, and so making a consolidated variable seems like a wise decision. For instance, on my machine, I have multiple python instances (sometimes I need an Anaconda installation of Python 3.6, and sometimes I want a version of the bare-bones Python 3.5). To accomodate this, I create environmental variables for the paths to each installation.
Now if I want to switch which version is on my path, I can simply update my path variable from
path=...;%PATH_PYTHON35%
to
path=...;%PATH_PYTHON36A%
See how easy that was?
The problem is that the GUI doesn't seem to like this for the local variables. I can confirm that this is the case because when I remove the variables from the local path, I get the nice list like the System Variables case. However, what is perplexing to me is that the System Variables path DOES include some variables as well:
So I take this to mean that there must be a way of getting the local variables list to pop up, just like the System Variables case...
Guess I'm late to the party, but this works for me:
PATH=C:\DATA\bin;%JAVA_HOME%\bin
whereas this does not work:
PATH=%JAVA_HOME%\bin;C:\DATA\bin
A speculation based on my own observations.
It seems list view is only presented when at least one of the first two entries begins either with a drive letter notation (like C:\) or a specific variable. I'm not sure which variables are considered "valid", but here are a few environmental variables that show up as list:
%USERPROFILE%+%LOCALAPPDATA%;aaa;bbb;
aaa;Q:\%LOCALAPPDATA%;bbb;
These however show up as a string:
%LOCALAPPDATA%+%USERPROFILE%;aaa;bbb;
aaa;bbb;%USERPROFILE%;
Not sure what makes %USERPROFILE% different, but i tried a few other variables instead of %LOCALAPPDATA% (%OS%, %HOMEDRIVE%) - result was the same.
I am using the latest version of TeamCity and I am trying to make a parameter specification that refers to parameters.
I tried making a select (combobox), where the options of the checkbox are referring to variables. This should be possible, as there is a "parameter" icon to the right of the box suggesting me that I can use parameters here.
The full setup is shown below.
However, when I want to run the build, the only options are literally %foo% and %bar% as if the parameters have not even been evaluated.
Instead I had expected the options to contain the values of the variables that they are pointing to.
What am I doing wrong here?
Might be a bit late, but this is how I did it:
I have a few parameters for holding passwords, e.g. 'mfgpwd'
And I refer to these in another parameter using the syntax:
mfgpwd=%system.mfgpwd%
(I'm using TeamCity 8.1.5)
When defining an environment variable (on Windows for me, maybe there is a more general guideline)
set MY_TOOL=C:\DevTools\bin\mytool.exe
if the tool is located on a path with spaces
set MY_TOOL=C:\Program Files (x86)\Foobar\bin\mytool.exe
should the environment variable already contain the necessary spaces?
That is, should it read:
set MY_TOOL="C:\Program Files (x86)\Foobar\bin\mytool.exe"
instead of the above version without spaces?
Note: In light of Joeys answer, I really should narrow this question to the examples I gave. That is, environment variables that contain one single (executable / batch) tool to be invoked by a user or by another batch script.
Maybe the spaces should be escaped differently?
I'd say, do it without quotes and use them everywhere you use the variable:
set MY_TOOL=C:\Program Files (x86)\Foobar\bin\mytool.exe
"%MY_TOOL%" -someoption someargument somefile
Especially if you let the user set the value somewhere I guess this is the safest option, since they usually tend not to surround it with quotes rather than do so.
If there are plenty of places where you use the variable you can of course redefine:
set MY_TOOL="%MY_TOOL%"
which makes things more resilient for you. Optionally you could detect whether there are quotes or not and add them if not present to be totally sure.
When your variable represents only a path to a directory and you want to append file names there, then the "no quotes" thing is even more important, otherwise you'd be building paths like
"C:\Program Files (x86)\Foobar\bin"\mytool.exe
or even:
""C:\Program Files (x86)\Foobar\bin"\my tool with spaces.exe"
which I doubt will parse correctly.
The command shell can answer your question: type C:\Pro and hit the tab key.
Autocomplete will leave all spaces as-is and add quotes around the filename. So, this is what is "officially" expected.
(this assumes that autocomplete is turned on, I'm not sure whether the default is on or off, but most people have it on anyway, I guess)