aboutsummaryrefslogtreecommitdiff
path: root/bin/without-env
diff options
context:
space:
mode:
Diffstat (limited to 'bin/without-env')
-rwxr-xr-xbin/without-env17
1 files changed, 15 insertions, 2 deletions
diff --git a/bin/without-env b/bin/without-env
index 57c2d2e..4e7ed15 100755
--- a/bin/without-env
+++ b/bin/without-env
@@ -4,7 +4,7 @@ set -eu
usage() {
cat <<-'EOF'
Usage:
- without-env ENVVAR PATH -- COMMAND...
+ without-env ENVVAR PATH COMMAND...
without-env -h
EOF
}
@@ -12,17 +12,30 @@ usage() {
help() {
cat <<-'EOF'
+
Options:
-h, --help show this message
+ ENVVAR the name of the environment variable to be modifed
+ PATH section to be excluded from ENVVAR
+ COMMAND command to be wrapped
+
+
+ Execute COMMAND, but changing the variable ENVVAR by excluding
+ PATH from it.
+
+
Examples:
Execute "command -V" filtering ~/bin, to get where "w3m" is
in $PATH, other than ~/bin:
+
$ without-env PATH ~/bin -- command -v w3m
+
Compile foo.c, excluding ~/.local/include
from $C_INCLUDE_PATH:
+
$ without-env C_INCLUDE_PATH ~/.local/include -- cc -co foo.o foo.c
EOF
}
@@ -60,7 +73,7 @@ shift $((OPTIND - 1))
eval "$(assert-arg -- "${1:-}" 'ENVVAR')"
eval "$(assert-arg -- "${2:-}" 'PATH')"
-eval "export $1=\"\$(echo \"\$$1\" | sed \"s|\$2:||g\")\""
+eval "export $1=\"\$(echo \"\$$1\" | sed \"s|\$2||g\")\""
shift # drop $1
shift # drop $2
if [ "${1:-}" = '--' ]; then