Changeset 95391 in vbox for trunk/tools/bin/RemoveDirFromPath.sh
- Timestamp:
- Jun 27, 2022 1:41:54 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/bin/RemoveDirFromPath.sh
r95375 r95391 2 2 # $Id$ 3 3 ## @file 4 # Bash function for removing a directory from the PATH. 5 # 6 # This is used by tools/env.sh but cannot be a part of it because kmk_ash 7 # freaks out when it sees the bash-specific substitutions. 4 # Shell (bash + kmk_ash) function for removing a directory from the PATH. 8 5 # 9 6 # Assumes KBUILD_HOST is set. … … 29 26 RemoveDirFromPath() 30 27 { 31 MY_SEP=$1 32 MY_DIR=$2 28 # Parameters. 29 local MY_SEP="$1" 30 local MY_DIR="$2" 33 31 if test "${KBUILD_HOST}" = "win"; then 34 32 MY_DIR="$(cygpath -u "${MY_DIR}")" 35 33 fi 36 34 37 # This should work at least back to bash 2.0 if the info page is anything to go by. 38 PATH="${MY_SEP}${PATH}${MY_SEP}" # Make sure there are separators at both ends. 39 PATH="${PATH//${MY_SEP}${MY_DIR}${MY_SEP}/${MY_SEP}}" # Remove all (=first '/') ${MY_DIR} instance. 40 PATH="${PATH#${MY_SEP}}" # Remove the leading separator we added above. 41 PATH="${PATH%${MY_SEP}}" # Remove the trailing separator we added above. 35 # Set the PATH components as script argument. 36 local MY_OLD_IFS="${IFS}" 37 IFS="${MY_SEP}" 38 set -- ${PATH} 39 IFS="${MY_OLD_IFS}" 40 41 # Iterate the components and rebuild the path. 42 PATH="" 43 local MY_SEP_PREV="" 44 local MY_COMPONENT 45 for MY_COMPONENT 46 do 47 if test "${MY_COMPONENT}" != "${MY_DIR}"; then 48 PATH="${PATH}${MY_SEP_PREV}${MY_COMPONENT}" 49 MY_SEP_PREV="${MY_SEP}" # Helps not eliminating empty entries. 50 fi 51 done 42 52 } 43 53
Note:
See TracChangeset
for help on using the changeset viewer.