How to list variables declared in script in bash?

后端 未结 14 983
走了就别回头了
走了就别回头了 2020-11-28 20:03

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 l

14条回答
  •  失恋的感觉
    2020-11-28 20:12

    Try using a script (lets call it "ls_vars"):

      #!/bin/bash
      set -a
      env > /tmp/a
      source $1
      env > /tmp/b
      diff /tmp/{a,b} | sed -ne 's/^> //p'
    

    chmod +x it, and:

      ls_vars your-script.sh > vars.files.save
    

提交回复
热议问题