1 | #!/usr/bin/env kmk_ash
|
---|
2 | # $Id: RemoveDirFromPath.sh 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # Shell (bash + kmk_ash) function for removing a directory from the PATH.
|
---|
5 | #
|
---|
6 | # Assumes KBUILD_HOST is set.
|
---|
7 | #
|
---|
8 |
|
---|
9 | #
|
---|
10 | # Copyright (C) 2020-2024 Oracle and/or its affiliates.
|
---|
11 | #
|
---|
12 | # This file is part of VirtualBox base platform packages, as
|
---|
13 | # available from https://www.virtualbox.org.
|
---|
14 | #
|
---|
15 | # This program is free software; you can redistribute it and/or
|
---|
16 | # modify it under the terms of the GNU General Public License
|
---|
17 | # as published by the Free Software Foundation, in version 3 of the
|
---|
18 | # License.
|
---|
19 | #
|
---|
20 | # This program is distributed in the hope that it will be useful, but
|
---|
21 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
23 | # General Public License for more details.
|
---|
24 | #
|
---|
25 | # You should have received a copy of the GNU General Public License
|
---|
26 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
27 | #
|
---|
28 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
29 | #
|
---|
30 |
|
---|
31 | ##
|
---|
32 | # Modifies the PATH variable by removing $1.
|
---|
33 | #
|
---|
34 | # @param 1 The PATH separator (":" or ";").
|
---|
35 | # @param 2 The directory to remove from the path.
|
---|
36 | RemoveDirFromPath()
|
---|
37 | {
|
---|
38 | # Parameters.
|
---|
39 | local MY_SEP="$1"
|
---|
40 | local MY_DIR="$2"
|
---|
41 | if test "${KBUILD_HOST}" = "win"; then
|
---|
42 | MY_DIR="$(cygpath -u "${MY_DIR}")"
|
---|
43 | fi
|
---|
44 |
|
---|
45 | # Set the PATH components as script argument.
|
---|
46 | local MY_OLD_IFS="${IFS}"
|
---|
47 | IFS="${MY_SEP}"
|
---|
48 | set -- ${PATH}
|
---|
49 | IFS="${MY_OLD_IFS}"
|
---|
50 |
|
---|
51 | # Iterate the components and rebuild the path.
|
---|
52 | PATH=""
|
---|
53 | local MY_SEP_PREV=""
|
---|
54 | local MY_COMPONENT
|
---|
55 | for MY_COMPONENT
|
---|
56 | do
|
---|
57 | if test "${MY_COMPONENT}" != "${MY_DIR}"; then
|
---|
58 | PATH="${PATH}${MY_SEP_PREV}${MY_COMPONENT}"
|
---|
59 | MY_SEP_PREV="${MY_SEP}" # Helps not eliminating empty entries.
|
---|
60 | fi
|
---|
61 | done
|
---|
62 | }
|
---|
63 |
|
---|