45 lines
647 B
Bash
Executable File
45 lines
647 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
INPUT="${1:?input file required}"
|
|
OUTPUT="${2:?output file required}"
|
|
|
|
mkdir -p "$(dirname "$OUTPUT")"
|
|
|
|
awk '
|
|
function trim(s) {
|
|
sub(/^[[:space:]]+/, "", s)
|
|
sub(/[[:space:]]+$/, "", s)
|
|
return s
|
|
}
|
|
|
|
BEGIN {
|
|
for (k in ENVIRON) {
|
|
env[k] = ENVIRON[k]
|
|
}
|
|
}
|
|
|
|
/^[[:space:]]*#/ || /^[[:space:]]*$/ {
|
|
print
|
|
next
|
|
}
|
|
|
|
{
|
|
line = $0
|
|
eq = index(line, "=")
|
|
|
|
if (eq == 0) {
|
|
print line
|
|
next
|
|
}
|
|
|
|
key = trim(substr(line, 1, eq - 1))
|
|
val = substr(line, eq + 1)
|
|
|
|
if (key in env) {
|
|
print key "=" env[key]
|
|
} else {
|
|
print line
|
|
}
|
|
}
|
|
' "$INPUT" > "$OUTPUT" |