Skip to content

Instantly share code, notes, and snippets.

@elfmimi
Created June 28, 2019 13:05
Show Gist options
  • Save elfmimi/60fde79c5065fba8c94f09add81f0ff5 to your computer and use it in GitHub Desktop.
Save elfmimi/60fde79c5065fba8c94f09add81f0ff5 to your computer and use it in GitHub Desktop.
path operation on bash
function path_remove () {
local IFS=:
local i A=($PATH)
for i in ${!A[*]}; do if [[ "${A[$i]}" == "$1" ]] ; then unset A[$i]; fi; done
export PATH="${A[*]}"
}
; in one line format
; function path_remove () { local IFS=: ; local i A=($PATH) ; for i in ${!A[*]} ; do if [[ "${A[$i]}" == "$1" ]] ; then unset A[$i] ; fi ; done ; export PATH="${A[*]}" ; }
function path_append () { path_remove "$1"; export PATH="$PATH:$1"; }
function path_prepend () { path_remove "$1"; export PATH="$1:$PATH"; }
; example
; path_remove "$(cygpath -u 'C:\Program Files (x86)\Windows Kits\8.1\bin\x64')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment