Uma solução usando comm
com base no armazenamento de todas as variáveis antes e depois:
#!/bin/bash
# Storing variables before:
set -o posix
set > $TMP/VariablesBefore.txt
sort $TMP/VariablesBefore.txt -o $TMP/VariablesBeforeSorted.txt
a=3
b=7
# Storing variables after:
set > $TMP/VariablesNow.txt
sort $TMP/VariablesNow.txt -o $TMP/VariablesNowSorted.txt
# Computing differences:
echo "The variables inside the script are: "
comm -3 $TMP/VariablesBeforeSorted.txt $TMP/VariablesNowSorted.txt
Bem, ainda existem algumas variáveis restantes como _
ou BASH_LINENO
, mas esta é a aposta que eu alcancei.
Note that this solution could not work in all cases, for example variables very long (KB), with
new line
codes, or variables including variable names. Thanks, MikeServ, for pointing.