Hi Busybox maintainers!
Here's a simple patch that introduces envsubst as an applet, and I feel like
it's so small (~470 bytes without whitespace) that it's okay to include. I
doubt a C implementation would be smaller or faster.
Busybox is frequently used in minimal container images. For CI/CD purposes, env
variables are often used and replaced in files using envsubst (from GNU
gettext).
However, busybox lacks this functionality, so people often have to include the
script in their images.
Could we maybe include it?
diff --git a/applets_sh/envsubst b/applets_sh/envsubst
new file mode 100755
index 000000000..d5141b146
--- /dev/null
+++ b/applets_sh/envsubst
@@ -0,0 +1,18 @@
+#! /usr/bin/awk -E
+BEGIN {
+ if (ARGC > 1 || ARGV[1] == "-h" || ARGV[1] == "--help" || ARGV[1] == "-v")
{
+ print "Busybox implementation of envsubst.\n\nUsage: envsubst <
[INPUT-FILE] > [OUTPUT-FILE]\n\nSubstitutes the values of environment variables
from stdin."
+ if (ARGV[1] == "-h" || ARGV[1] == "--help" || ARGV[1] == "-v") {exit
0} else {exit 1}
+ }
+}
+{
+ while (match($0, /\$\w+|\${\w+}/)) {
+ start = RSTART
+ len = RLENGTH
+ var = substr($0, start + 1, len - 1)
+ gsub(/[{}]/, "", var)
+ value = ENVIRON[var]
+ $0 = substr($0, 1, start - 1) value substr($0, start + len)
+ }
+ print
+}
_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox