0

Is there any way to print all the variables declared and used within a Bash script?

For example printf "%s\n" "${FUNCNAME[@]}" will print the names of all shell functions currently in the execution call stack.

Ex: This is my script content (there must be a lot of declared variables):

#!/bin/bash

say_hello() {
    name="$1"
    echo "Hello $name"
}

my_name="Luis Daniel"
my_age="29"

say_hello "$my_name"

Then, I need to log something like this:

my_name = Luis Daniel
my_age = 29
name = Luis Daniel
Luis Daniel
  • 687
  • 7
  • 18
  • Look at the [set](http://linuxcommand.org/lc3_man_pages/seth.html) or [env](https://linux.die.net/man/1/env) commands. – paulsm4 Mar 05 '19 at 21:56
  • No, "set" shows a lot of information that I do not need, I just need to register in a log file all the variables declared and used in the script – Luis Daniel Mar 05 '19 at 22:02
  • Dude, you didn't specify that in your question. You have *MANY* options: including "set", "env", "printenv", "declare -x", etc. etc. You can also use any of these options *IN CONJUNCTION* with other commands like "sed", "grep" and/or "awk". – paulsm4 Mar 05 '19 at 22:05
  • 2
    Possible duplicate of [How to list variables declared in script in bash?](https://stackoverflow.com/questions/1305237/how-to-list-variables-declared-in-script-in-bash). Use `( set -o posix ; set )` or `declare -p`. – Socowi Mar 05 '19 at 22:06

0 Answers0