How to list variables declared in script in bash?

后端 未结 14 984
走了就别回头了
走了就别回头了 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:26

    Try this : set | egrep "^\w+=" (with or without the | less piping)

    The first proposed solution, ( set -o posix ; set ) | less, works but has a drawback: it transmits control codes to the terminal, so they are not displayed properly. So for example, if there is (likely) a IFS=$' \t\n' variable, we can see:

    IFS='
    '
    

    …instead.

    My egrep solution displays this (and eventually other similars ones) properly.

提交回复
热议问题