powershell - Variable not updating when function is called -
i have in profile script.
$addablepaths = @{ "python3"=";c:\python32"; "python2"=";c:\python27"; "d"=";c:\d\dmd2\windows\bin"; "gcc"=";c:\mingw\bin"; "verge"=";c:\users\cold\dev\verge\tools"; "ruby"=";c:\ruby192\bin"; "git"=";c:\program files\git\cmd"; "cmake"=";c:\program files\cmake 2.8\bin"; "emacs"=";c:\users\cold\dev\emacs\bin"; "notepad++"=";c:\program files\notepad++"; "boost-build"=";c:\users\cold\dev\c++\boost-build\bin"; "svn"=";c:\program files\sliksvn\bin"; "gtk2"=";c:\program files\gtk2-runtime\bin"; "qt"=";c:\qt\bin"; "komodo"=";c:\program files\activestate komodo edit 6\"; "hg"=";c:\program files\tortoisehg\" } $addedpaths = @() function addpath($keys) { if ($keys.count -eq 0) { return } foreach ($key in $keys) { if ($addablepaths.contains($key)) { if (!($addedpaths -contains $key)) { $env:path += $addablepaths[$key] $addedpaths += $key } } else { write-host "invalid path option. options are:" foreach ($key in $addablepaths.keys) { write " $key" } } } }
it's purpose allow me able add path things need. example, can call addpath("ruby","git","notepad++")
add 3 things path. want doesn't add items if added them, created $addedpaths
array keep track of what's been added already. however, doesn't update when call function, duplicates can still added. doing wrong?
you'll need this:
$global:addedpathes += $key
that should place need $global:
since modifies it.
Comments
Post a Comment