In my script in bash, there are lot of variables, and I have to make something to save them to file. My question is how to list all variables declared in my script and get list like this:
VARIABLE1=abc VARIABLE2=def VARIABLE3=ghi
set will output the variables, unfortunately it will also output the functions defines as well.
Luckily POSIX mode only outputs the variables:
( set -o posix ; set ) | less
less, or redirect to where you want the options.
So to get the variables declared in just the script:
( set -o posix ; set ) >/tmp/variables.before source script ( set -o posix ; set ) >/tmp/variables.after diff /tmp/variables.before /tmp/variables.after rm /tmp/variables.before /tmp/variables.after
(Or at least something based on that :-) )
It lists all variables including local ones. I learned it from Get list of variables whose name matches a certain pattern, and used it in my script.