I want to print all environment variables except certain variables.
Therefore I found a solution on stackoverflow: Bash: loop through variables containing pattern in name
while IFS='=' read -r name value; do
if [ ! "$name" = "SOMEVAR" -a ! "$name" = "SOMEOTHERVAR" ]; then
echo "$name=$value"
fi
done < <(env)
However this does not work if my environment variables contain newlines, such as:
export SOMEVAR="some
text with
newlines"
With the above solution it would print:
text with=
newlines=
PWD=/home/...
...
I also tried to use null-terminated strings and multiline matching with sed:
env -0 | sed -e '{N; s@SOMEVAR.*\x0@@ ; D}' | tr '\0' '\n'
But this cuts off the output and always prints the last line of a variable with multiline content at first:
newlines
PWD=/home/...
...
Is there any way to skip multiline environment variables while printing them?