Just making sure I understand correctly: you want to edit the user-scope PATH variable, but don't want to add all the stuff from the system-scope copy of PATH to your user-scope one?
The best way I know of to do this is actually to use Powershell. Yes, I know you tagged this as bash
, but I'm pretty sure you didn't mean to; setx
is a Windows command. :-)
[System.Environment]::GetEnvironmentVariable("PATH","USER")
will get the current-user-scope PATH environment variable as a string. You can then append to this and store it back using the SetEnvironmentVariable
function.
$userpath = [System.Environment]::GetEnvironmentVariable("PATH","USER")
$userpath = $userpath + ";D:\Myfolder\Test\"
[System.Environment]::SetEnvironmentVariable("PATH",$userpath,"USER")
You can read more about messing with environment variables at this SuperUser question.
Note that, like the setx
command, this won't actually change any environment variables in the current process. If you want to do that, you can use "PROCESS"
instead of "USER"
in a call to SetEnvironmentVariable
, or just append your value to $ENV:PATH
, something like $ENV:PATH = $ENV:PATH + ";D:\Myfolder\Test\"