I think this is just simple and really googling around does give a lot of answers but not sure why it's not working for me.
Firstly without any ENV PATH = set, I can check that the PATH has a default value of
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\ContainerAdministrator\AppData\Local\Microsoft\WindowsApps
I check that by simply running the image and use CMD echo %PATH%.
However with the following setting, all the default is gone letting the new value alone (looks really like that it cannot get the default value or simply that value is empty):
ENV PATH = "C:\Program Files\dotnet\:${PATH}"
Here are various attempts (not working):
#this even tries removing spaces around the =
#like some ones warned that could break the PATH
ENV PATH="C:\Program Files\dotnet:${PATH}"
ENV PATH = "C:\Program Files\dotnet\:$PATH"
ENV PATH = "C:\Program Files\dotnet:${PATH}"
ENV PATH = "C:\Program Files\dotnet:$PATH"
ENV PATH = "C:\Program Files\dotnet;${PATH}"
ENV PATH = "C:\Program Files\dotnet;$PATH"
ENV PATH = "C:\Program Files\dotnet;$env:PATH"
With one of the above setting, the PATH (checked by echo %PATH% when executing cmd on a running container) becomes just C:\Program Files\dotnet (maybe with some more characters appended for some cases).
Really I would like to bang my head against the wall for such a simple issue but has taken me hours. Really?
And here is the full dockerfile:
# escape=`
FROM microsoft/dotnet:2.1-sdk-nanoserver-1803 AS dotnet
FROM microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-1803
ENV DOTNET_PATH="C:\Program Files\dotnet"
COPY --from=dotnet ${DOTNET_PATH} ${DOTNET_PATH}
ENV PATH = "C:\Program Files\dotnet\:${PATH}"
ENV ASPNETCORE_URLS=http://+:80 `
DOTNET_RUNNING_IN_CONTAINERS=true `
DOTNET_SKIP_FIRST_TIME_EXPERIENCE="true"
I hope someone here could point out what's wrong. Thanks!
RUN setx /M PATH "C:\Program Files\dotnet;%PATH%"
In fish, say I have a file path from somewhere:
/aaa/bbb/ccc.txt
How can I get the full path of its parent dir? So I will get:
/aaa/bbb
This is the dirname command, and it is a Unix utility, not specific to fish.
For example, cd (dirname /aaa/bbb/ccc.txt)
I'd like to set a file's name to a variable in a batch file. I'm already pulling the file name by pulling the total path length. Is there a way I can parse the path to only give me back the file name?
The particular script that I use to pull the path looks like this:
for /f "delims=_" %%J IN ('forfiles /p "%%F" /m *.extension /c "cmd /c echo #path"')
DO start "Program" /D "c:\fullpath" /Wait program -r %%J
Also, if there's an easier way to pull the file name and put it into a variable I'm open to that as well.
I installed rbenv through homebrew, and now I don't know why path_helper put ~/.rbenv/shims at the end of the path instead of the beginning. And most importantly, how did path_helper get this information?
According to the man page of path_helper, it reads entries from /etc/paths and from files in /etc/paths.d. But I cannot find the string ".rbenv/shims" there.
~% cat /etc/paths
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
~% ls -la /etc/paths.d
total 0
drwxr-xr-x 2 root wheel 68 Jun 21 03:16 .
drwxr-xr-x 107 root wheel 3638 Sep 10 09:59 ..
~% /usr/libexec/path_helper
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/gordon/.rbenv/shims"; export PATH;
I suspect that your .bash_profile or .bashrc is adding
.rbenv/shims to your PATH, and that is running at some point before
path_helper is invoked during the shell start-up.
The man page for path_helper opens with:
The path_helper utility reads the contents of the files in the directo-
ries /etc/paths.d and /etc/manpaths.d and appends their contents to the
PATH and MANPATH environment variables respectively.
The crucial point here is that the path_helper utility is intended to
add contents to an existing PATH setting, not replace them. (And in
actuality, what it really does is prepend contents, not append them,
which matters for PATH variables...)
So, if I start out with an entry on my PATH, the setting generated by
path_helper will ensure that entry continues on the PATH it generates.
% echo $SHELL
/bin/bash
% uname
Darwin
% /usr/libexec/path_helper
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"; export PATH;
% PATH="" /usr/libexec/path_helper
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"; export PATH;
% PATH=foo /usr/libexec/path_helper
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:foo"; export PATH;
Note that foo has been included in my PATH in the last line, even though
the contents of /etc/paths and /etc/paths.d/* have not changed.
At the same time, the path_helper utility also seems to be careful not
to produce paths with duplicate entries; it removes duplicate entries
after concatenating /etc/paths and /etc/paths.d/* and the current
PATH.
This latter detail can be especially confusing since it can cause
entry reorderings compared to the original PATH setting (!).
Below are some examples of this behavior: The first case shows a duplicate foo being removed. The second and third case illustrate entry reordering: the generated PATH is the same in both cases, but in the third case, the /usr/bin entry has been moved from in-between foo and bar to the front of the PATH. (This duplicate-entry removal seems to be based on just simple string-matching on the pairs of entries, as illustrated by the fourth case below where the string /usr/bin/ remains between foo/ and bar.)
% PATH=foo:foo /usr/libexec/path_helper
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:foo"; export PATH;
% PATH=foo:bar /usr/libexec/path_helper
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:foo:bar"; export PATH;
% PATH=foo:/usr/bin:bar /usr/libexec/path_helper
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:foo:bar"; export PATH;
% PATH=foo/:/usr/bin/:bar /usr/libexec/path_helper
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:foo/:/usr/bin/:bar"; export PATH;
Finally, to give credit where credit is due:
While all of the command sequences above are the result of my own investigations, I was originally inspired to look into the behavior of path_helper after reading the note here,
which pointed out that path_helper reuses the PATH environment variable set by the parent process.
The path_helper man page is incorrect. The man page says path_helper is appending /etc/paths.d onto the PATH. But actually, path_helper is APPENDing /etc/paths.d onto the list from /etc/paths and then effectively PREPENDing that result onto actual pre-existing PATH (as well as purging PATH of overridden duplicates from that list).
To be exact, speaking only of PATH for instance, what it does is:
read the list of paths in the file /etc/paths
APPEND onto it the lists of paths in the files in the directory /etc/paths.d
mutate the PATH variable to remove any items in the list
APPEND onto the list the value of the mutated PATH variable
Save this list as the new PATH
To rephrase this in pseudocode, what it's doing is:
NEWPATH = Read(/etc/paths)
NEWPATH = $NEWPATH +append+ Read(/etc/paths.d/*)
PATH = $PATH -minus- $NEWPATH
NEWPATH = $NEWPATH +append+ $PATH
PATH = $NEWPATH
What's treacherous about this is that, if you are manually configuring your PATH, it's probably in order to add components that override system path components. If path_helper gets called when you don't expect it, then it will undo your changes by putting the system-wide path components ahead of your path components.
How would path helper get called unexpectedly? For instance, it gets called by /etc/zshenv, which is called every time you start a zsh shell, whether it's a subshell, or a zsh instance called from another app like emacs, or whatever.
I've written it in more detail as an OpenRadar bug report on path_helper.
I want to set an environment variable that has space in it.
It is a path to a folder and the folder name is:
/home/mehrabib/my video
I edit .bashrc and add the following line to it:
export $VIDEO=/home/mehrabib/my\ video
and run these commands:
echo $VIDEO
cd $VIDEO
The result is:
/home/mehrabib/my video
/home/mehrabib/my :no such file or directory
I change it to
export $VIDEO=/home/mehrabib/my\\\ video
and run these commands:
echo $VIDEO
cd $VIDEO
The result is:
/home/mehrabib/my\ video
/home/mehrabib/my\ :no such file or directory
What should I do?
You should do
export VIDEO="/home/mehrabib/my video"
and to sum Dan's comments up also do
cd "$VIDEO"
which will expand to
cd "/home/mehrabib/my video"
again.
Personally, I've come to prefer the ${VIDEO} syntax.
You can also substitute special characters - use * as a wildcard to substitute for the space.
VIDEO="/home/mehrabib/m*o"
Try to quote VIDEO: cd "$VIDEO".