What is the difference between the PATH listed by 'env' in git-bash and the PATH in Windows 10's control panel? - shell

My goal is to write a shell script that will ensure that a bunch of Windows 10 computers with Python freshly installed on them can run the 'python' command from a git-bash command line in Windows Terminal by having the script check the PATH environment variable and modify it if necessary.
More specifically, I want my script to check if the following three paths are part of each computer's PATH, and if they aren't already a part of it, edit the PATH so that it permanently contains them.
C:\Program Files\Python311
C:\Program Files\Python311\Scripts
C:\Users\ <localUser>\AppData\Roaming\Python\Python311\Scripts
What threw me off is that I noticed that the PATH variable that I get from the 'env' command on the git-bash command line is different from the PATH variable that I can see in Windows 10's control panel. I tried adding a junk path to PATH from the command line by typing
export PATH=/c/someNonexistentPath in git bash but it didn't change the PATH that I could see in the Windows 10 control panel. Moreover, I couldn't even see if it changed the PATH I get from running env on the command line because for some reason after you run any export command git-bash gets amnesia and refuses to recognize the env command until you start a new session of git-bash.
Shouldn't there only be one PATH on a computer? If the two seemingly different PATHs that I have mentioned are not supposed to be the same, what is the difference between them, and how can I accomplish my goal of writing the script so that it does what I need it to do?
Please let me know if I need to include any more system-specific info. Thanks in advance for your help.

Related

Restore the previous system path variable (windows)

a question regarding messing with Windows Path variable.
My situation is quite specific:
I was trying to install ffmpeg according to this tutorial https://www.geeksforgeeks.org/how-to-install-ffmpeg-on-windows/
The last step was setting the path variable setx /m PATH "C:\ffmpeg\bin;%PATH%"
It worked, however afterwards I noticed that if I try to call python from the command prompt or the powershell if run as administrator, I started getting 'chcp' is not recognized as an internal or external command, (although works fine if run as user), indicating that something is wrong with PATH variables.
I looked into my variables and saw this edit.
Path
It seems to me that the command added the ffmpeg line to the system path and possibly overwritten the original, which is why there are issues when using command prompt as administrator. It probably should have added it to the user Path (not system Path variable)
If that is the case, is there a way to restore the previous system Path variable. Maybe I can paste it from the user Path variable?

Setting default path with custom variable in windows 10pro

I have been trying to get windows to recognize shortcuts for developer tools. Things like adb for C:\Users\myusername\Andriod\platform-tools\adb.exe. I have tried using CMD and Powershell but they both don't add the PATH I tried the GUI and it doesn't show up.
I've tried setx path "%PATH%;C:\path\to\C:\Users\myusername\Andriod\platform-tools\adb.exe" in powershell and cmd then restarted powershell or cmd
input the variable adb but it pulls a command not recognized error.
Did you try the following?
Adding the path "C:\Users\myusername\Andriod\platform-tools" to your system/user PATH variable? You can do this by start-> environment variable -> environment variable and under system or user, edit the PATH variable and add the above link. Once you do this, restart CMD for it to work.
Add the executable in one of the already existing locations that are in the PATH variable. (Although this is one method, I would not suggest this). Again, if the executable has any dependencies, it must be in a place where the exe itself can access.

python virtualenvwrapper producing an EOL error on install

I was trying to use the pip package
virtualenvwrapper
in Windows through gitbash. The standard virtualenvwrapper-win doesn't work in gitbash and it's useful to not have to switch between consoles so I generally install both.
Normally you simply need to open your .bashrc file in your home directory and type something akin to the following:
export WORKON_HOME=$HOME/Envs/
source Path/To/Python/Scripts/virtualenvwrapper.sh
In this case, however, this produced an error complaining that it reached EOL (end of line) while scanning the string literal. It showed the offending line and it was trying to combine the gitbash $HOME variable (with forward slashes) with the windows environment variable (with the backslashes).
How can I fix it so that it's not combining the environment variables?
The first solution is to manually force the script to find the right path by opening virtualenvwrapper.sh and editing line 126:
"$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write('/path/to/your/envs/folder')"
The underlying cause, however, occurs if you try to set an environment variable in windows for WORKON_HOME. If you simply want to share the Envs folder in your home directory, delete the WORKON_HOME environment variable you created in windows and the issue should go away.
If you want it in a completely different place, then use the absolute path (no environment variables such as %USERPROFILE%) in the windows environment variable and it should work.

External commands not available in gvim on windows

When starting a gvim session on windows 7, it appears that globally available commands like autopep8 or pylint cannot be executed. I.e. the command :!pylint opens up a console windows saying 'pylint' is not recognized as an internal or external command.
However, I can execute these commands from cmd.exe by just typing the respective names.
This is because I have added the path C:\Program Files (x86)\Python 3.5\Scripts; to the System Path environment variable. For some reason this is not picked up by the shell behind gvim.
The weird thing is that typing :echo $PATH shows a list or folders which includes C:\Program Files (x86)\Python 3.5\Scripts;.
I should also note that this problem does not occur when starting normal vim in a terminal like cmd.exe or git bash.
Any hints on what might be going wrong?

attempting to assign alias to path of an exe file in dos shell

I want to set an alias to my installation of firefox so I can easily start a web page, the problem is that I dont want the script to be system dependent.
Namely I want it to be able to run on a linux distribution where the command to start firefox is already mapped to 'firefox' and can easily be run that way through bash, but on my windows machine I cant seem to get it to assign to the same variable.
I saw that I could set it to '%firefox%' via the set command but that's not quite what I want.
I believe creating aliases is possible on a windows environment because the version of svn that I use auto-installed and was able to assign itself to 'svn'. Anyone know what was involved in them being able to get their alias working, or a similar way to alias a command?
If you include your Firefox path in the %PATH% environment variable, you can start FF with "firefox". Under Windows, you should edit the system-wide settings (see this link).
AFAIK, there is nothing similar to aliases under DOS/Windows (except the %firefox% way you mentioned, too). The 'svn' command you talked about most likely is the same thing, a 'svn.exe' and its path included to %PATH%.
This is a bit restrictive, as you can only use the original filename to launch a program, but you can work around this by creating a batch file in the program's path that launches the program, f.e. a FF.BAT that contains "firefox %1".
Alternatively, you can place a batch file in a path that already is in %PATH%, f.e. the Windows directory. That way, you don't have to modify %PATH%.

Resources