substenv - Substitute environment variables in parameters and run the resulting command



NAME

substenv - Substitute environment variables in parameters and run the resulting command


SYNOPSIS

substenv [OPTIONS] [--] COMMAND [ARGS]


DESCRIPTION

Replace all occurrances of $NAME in COMMAND and ARGS to the NAME environment variable's value, whatever NAME would be, then run COMMAND ARGS. Support ${NAME} curly bracket notation too.


OPTIONS

-a, --all

Replace all occurrances of any $NAME (and ${NAME}) substring (for details see LIMITATIONS). This is the default behaviur, unless -e is given.

-e, --environment NAME

Replace the occurrances of NAME environment variable. May be specified more than once. If -a option is NOT given, ONLY these NAMEs are replaced.

-k, --keep-undefined

Do not replace variables which are not defined (ie. not in the environment), but keep them as-is. By default they are replaced with the empty string.

--dryrun, --dry-run

Do not run COMMAND, just print what would be executed.


EXAMPLE

This function call, in C, runs substenv(1), note, there is no dollar-interpolation in C.

 execve("substenv", ["substenv", "ls", "$HOME/.config"])

Then substenv issues this system call:

 execve("ls", ["ls", "/home/jdoe/.config"])


LIMITATIONS

In "substitute all" mode (without -e flag) it replaces only names with uppercase letters, digits, and underscore ([A-Z0-9_]+), as env vars usually contain only these chars. However it still replaces variables with lowercase letters in ${NAME} notation, and specific variable(s) given in -e option(s).

Does not honour escaped dollar marks, ie. \$.


NOTES

Does not support full shell-like variable interpolation. Use a real shell for it.


RATIONALE

Sometimes you don't want a shell to be in the picture when composing commands, yet need to weave some environment variable into it.


SEE ALSO

envsubst(1) from gettext-base package