How can I list all shell variables?











up vote
15
down vote

favorite
6












Reading about this question: In zsh how can I list all the environment variables?, I wondered, how can I list all the shell variables?



Also, does the distinction between shell variables and environment variables apply to shells other than zsh?



I am primarily interested in Bash and Zsh, but it would be great to know how to do this in other mainstream shells.










share|improve this question




























    up vote
    15
    down vote

    favorite
    6












    Reading about this question: In zsh how can I list all the environment variables?, I wondered, how can I list all the shell variables?



    Also, does the distinction between shell variables and environment variables apply to shells other than zsh?



    I am primarily interested in Bash and Zsh, but it would be great to know how to do this in other mainstream shells.










    share|improve this question


























      up vote
      15
      down vote

      favorite
      6









      up vote
      15
      down vote

      favorite
      6






      6





      Reading about this question: In zsh how can I list all the environment variables?, I wondered, how can I list all the shell variables?



      Also, does the distinction between shell variables and environment variables apply to shells other than zsh?



      I am primarily interested in Bash and Zsh, but it would be great to know how to do this in other mainstream shells.










      share|improve this question















      Reading about this question: In zsh how can I list all the environment variables?, I wondered, how can I list all the shell variables?



      Also, does the distinction between shell variables and environment variables apply to shells other than zsh?



      I am primarily interested in Bash and Zsh, but it would be great to know how to do this in other mainstream shells.







      bash zsh environment-variables






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 at 22:42









      Isaac

      9,91111445




      9,91111445










      asked Dec 26 '14 at 13:48









      Josh

      772825




      772825






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          15
          down vote



          accepted










          List all shell variables



          bash : use set -o posix ; set. The POSIX options is there to avoid outputting too much information, like function definitions. declare -p also works.



          zsh : use typeset



          Shell variables and environment variables



          An environment variable is available to exec()-ed child processes (as a copy. if parent process change the variable, the child environment is not updated). A non-environment variable is only available to the current running shell and fork()-ed subshells.



          (completed thanks to comments)






          share|improve this answer























          • declare -p do the same
            – Costas
            Dec 26 '14 at 14:02












          • The question also has an answer here : stackoverflow.com/questions/1305237/…
            – Uriel
            Dec 26 '14 at 14:05






          • 1




            set -o posix doesn't exist in zsh; set doesn't output function definitions.
            – vinc17
            Dec 26 '14 at 14:33






          • 1




            set -o posix is a syntax error in most shells.
            – mikeserv
            Dec 26 '14 at 18:29






          • 2




            Shell variables are also available in child processes. The difference comes when the child process executes a new program: environment variables are passed along in exec, shell variables are not.
            – Barmar
            Dec 31 '14 at 19:03




















          up vote
          6
          down vote













          There are many alternatives:



          printenv




          Print the values of the specified environment VARIABLE(s). If no VARIABLE is specified, print name and value pairs for them all.




          env




          env - run a program in a modified environment




          export




          Set an environment variable. Mark each name to be passed to child processes in the environment.....



          -p Display output in a form that may be reused as input.



          If no names are supplied, or if the `-p' option is given, a list of exported names is displayed.




          set



          is useful to get shell variables as well.



          If you need extra info (integer, exported) you should instead use



          typeset



          export has an advantage, that its output can be immediately read back onto the shell.



          Lastly, there is



          compgen -v




          Display possible completions depending on the options.




          which shows all variables, shell and environment, without their value or extra info. You will have to echo $VARIABLE_NAME to find the variable value. But at least the list is complete. It belongs to bash, not zsh.






          share|improve this answer



















          • 1




            export has no advantage over set, at least, when it comes to quoting for shell re-entry. And printenv and env are not at all about shell variables, though these do often coincide with environment variables.
            – mikeserv
            Dec 26 '14 at 17:05




















          up vote
          3
          down vote













          With zsh, you can use typeset, which gives more information than set, e.g. the type of the variables. You can still filter the output with grep or sed, depending on what you want. Environment variables are marked as exported in the output.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f176001%2fhow-can-i-list-all-shell-variables%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            15
            down vote



            accepted










            List all shell variables



            bash : use set -o posix ; set. The POSIX options is there to avoid outputting too much information, like function definitions. declare -p also works.



            zsh : use typeset



            Shell variables and environment variables



            An environment variable is available to exec()-ed child processes (as a copy. if parent process change the variable, the child environment is not updated). A non-environment variable is only available to the current running shell and fork()-ed subshells.



            (completed thanks to comments)






            share|improve this answer























            • declare -p do the same
              – Costas
              Dec 26 '14 at 14:02












            • The question also has an answer here : stackoverflow.com/questions/1305237/…
              – Uriel
              Dec 26 '14 at 14:05






            • 1




              set -o posix doesn't exist in zsh; set doesn't output function definitions.
              – vinc17
              Dec 26 '14 at 14:33






            • 1




              set -o posix is a syntax error in most shells.
              – mikeserv
              Dec 26 '14 at 18:29






            • 2




              Shell variables are also available in child processes. The difference comes when the child process executes a new program: environment variables are passed along in exec, shell variables are not.
              – Barmar
              Dec 31 '14 at 19:03

















            up vote
            15
            down vote



            accepted










            List all shell variables



            bash : use set -o posix ; set. The POSIX options is there to avoid outputting too much information, like function definitions. declare -p also works.



            zsh : use typeset



            Shell variables and environment variables



            An environment variable is available to exec()-ed child processes (as a copy. if parent process change the variable, the child environment is not updated). A non-environment variable is only available to the current running shell and fork()-ed subshells.



            (completed thanks to comments)






            share|improve this answer























            • declare -p do the same
              – Costas
              Dec 26 '14 at 14:02












            • The question also has an answer here : stackoverflow.com/questions/1305237/…
              – Uriel
              Dec 26 '14 at 14:05






            • 1




              set -o posix doesn't exist in zsh; set doesn't output function definitions.
              – vinc17
              Dec 26 '14 at 14:33






            • 1




              set -o posix is a syntax error in most shells.
              – mikeserv
              Dec 26 '14 at 18:29






            • 2




              Shell variables are also available in child processes. The difference comes when the child process executes a new program: environment variables are passed along in exec, shell variables are not.
              – Barmar
              Dec 31 '14 at 19:03















            up vote
            15
            down vote



            accepted







            up vote
            15
            down vote



            accepted






            List all shell variables



            bash : use set -o posix ; set. The POSIX options is there to avoid outputting too much information, like function definitions. declare -p also works.



            zsh : use typeset



            Shell variables and environment variables



            An environment variable is available to exec()-ed child processes (as a copy. if parent process change the variable, the child environment is not updated). A non-environment variable is only available to the current running shell and fork()-ed subshells.



            (completed thanks to comments)






            share|improve this answer














            List all shell variables



            bash : use set -o posix ; set. The POSIX options is there to avoid outputting too much information, like function definitions. declare -p also works.



            zsh : use typeset



            Shell variables and environment variables



            An environment variable is available to exec()-ed child processes (as a copy. if parent process change the variable, the child environment is not updated). A non-environment variable is only available to the current running shell and fork()-ed subshells.



            (completed thanks to comments)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 23 at 22:08

























            answered Dec 26 '14 at 13:59









            Uriel

            74445




            74445












            • declare -p do the same
              – Costas
              Dec 26 '14 at 14:02












            • The question also has an answer here : stackoverflow.com/questions/1305237/…
              – Uriel
              Dec 26 '14 at 14:05






            • 1




              set -o posix doesn't exist in zsh; set doesn't output function definitions.
              – vinc17
              Dec 26 '14 at 14:33






            • 1




              set -o posix is a syntax error in most shells.
              – mikeserv
              Dec 26 '14 at 18:29






            • 2




              Shell variables are also available in child processes. The difference comes when the child process executes a new program: environment variables are passed along in exec, shell variables are not.
              – Barmar
              Dec 31 '14 at 19:03




















            • declare -p do the same
              – Costas
              Dec 26 '14 at 14:02












            • The question also has an answer here : stackoverflow.com/questions/1305237/…
              – Uriel
              Dec 26 '14 at 14:05






            • 1




              set -o posix doesn't exist in zsh; set doesn't output function definitions.
              – vinc17
              Dec 26 '14 at 14:33






            • 1




              set -o posix is a syntax error in most shells.
              – mikeserv
              Dec 26 '14 at 18:29






            • 2




              Shell variables are also available in child processes. The difference comes when the child process executes a new program: environment variables are passed along in exec, shell variables are not.
              – Barmar
              Dec 31 '14 at 19:03


















            declare -p do the same
            – Costas
            Dec 26 '14 at 14:02






            declare -p do the same
            – Costas
            Dec 26 '14 at 14:02














            The question also has an answer here : stackoverflow.com/questions/1305237/…
            – Uriel
            Dec 26 '14 at 14:05




            The question also has an answer here : stackoverflow.com/questions/1305237/…
            – Uriel
            Dec 26 '14 at 14:05




            1




            1




            set -o posix doesn't exist in zsh; set doesn't output function definitions.
            – vinc17
            Dec 26 '14 at 14:33




            set -o posix doesn't exist in zsh; set doesn't output function definitions.
            – vinc17
            Dec 26 '14 at 14:33




            1




            1




            set -o posix is a syntax error in most shells.
            – mikeserv
            Dec 26 '14 at 18:29




            set -o posix is a syntax error in most shells.
            – mikeserv
            Dec 26 '14 at 18:29




            2




            2




            Shell variables are also available in child processes. The difference comes when the child process executes a new program: environment variables are passed along in exec, shell variables are not.
            – Barmar
            Dec 31 '14 at 19:03






            Shell variables are also available in child processes. The difference comes when the child process executes a new program: environment variables are passed along in exec, shell variables are not.
            – Barmar
            Dec 31 '14 at 19:03














            up vote
            6
            down vote













            There are many alternatives:



            printenv




            Print the values of the specified environment VARIABLE(s). If no VARIABLE is specified, print name and value pairs for them all.




            env




            env - run a program in a modified environment




            export




            Set an environment variable. Mark each name to be passed to child processes in the environment.....



            -p Display output in a form that may be reused as input.



            If no names are supplied, or if the `-p' option is given, a list of exported names is displayed.




            set



            is useful to get shell variables as well.



            If you need extra info (integer, exported) you should instead use



            typeset



            export has an advantage, that its output can be immediately read back onto the shell.



            Lastly, there is



            compgen -v




            Display possible completions depending on the options.




            which shows all variables, shell and environment, without their value or extra info. You will have to echo $VARIABLE_NAME to find the variable value. But at least the list is complete. It belongs to bash, not zsh.






            share|improve this answer



















            • 1




              export has no advantage over set, at least, when it comes to quoting for shell re-entry. And printenv and env are not at all about shell variables, though these do often coincide with environment variables.
              – mikeserv
              Dec 26 '14 at 17:05

















            up vote
            6
            down vote













            There are many alternatives:



            printenv




            Print the values of the specified environment VARIABLE(s). If no VARIABLE is specified, print name and value pairs for them all.




            env




            env - run a program in a modified environment




            export




            Set an environment variable. Mark each name to be passed to child processes in the environment.....



            -p Display output in a form that may be reused as input.



            If no names are supplied, or if the `-p' option is given, a list of exported names is displayed.




            set



            is useful to get shell variables as well.



            If you need extra info (integer, exported) you should instead use



            typeset



            export has an advantage, that its output can be immediately read back onto the shell.



            Lastly, there is



            compgen -v




            Display possible completions depending on the options.




            which shows all variables, shell and environment, without their value or extra info. You will have to echo $VARIABLE_NAME to find the variable value. But at least the list is complete. It belongs to bash, not zsh.






            share|improve this answer



















            • 1




              export has no advantage over set, at least, when it comes to quoting for shell re-entry. And printenv and env are not at all about shell variables, though these do often coincide with environment variables.
              – mikeserv
              Dec 26 '14 at 17:05















            up vote
            6
            down vote










            up vote
            6
            down vote









            There are many alternatives:



            printenv




            Print the values of the specified environment VARIABLE(s). If no VARIABLE is specified, print name and value pairs for them all.




            env




            env - run a program in a modified environment




            export




            Set an environment variable. Mark each name to be passed to child processes in the environment.....



            -p Display output in a form that may be reused as input.



            If no names are supplied, or if the `-p' option is given, a list of exported names is displayed.




            set



            is useful to get shell variables as well.



            If you need extra info (integer, exported) you should instead use



            typeset



            export has an advantage, that its output can be immediately read back onto the shell.



            Lastly, there is



            compgen -v




            Display possible completions depending on the options.




            which shows all variables, shell and environment, without their value or extra info. You will have to echo $VARIABLE_NAME to find the variable value. But at least the list is complete. It belongs to bash, not zsh.






            share|improve this answer














            There are many alternatives:



            printenv




            Print the values of the specified environment VARIABLE(s). If no VARIABLE is specified, print name and value pairs for them all.




            env




            env - run a program in a modified environment




            export




            Set an environment variable. Mark each name to be passed to child processes in the environment.....



            -p Display output in a form that may be reused as input.



            If no names are supplied, or if the `-p' option is given, a list of exported names is displayed.




            set



            is useful to get shell variables as well.



            If you need extra info (integer, exported) you should instead use



            typeset



            export has an advantage, that its output can be immediately read back onto the shell.



            Lastly, there is



            compgen -v




            Display possible completions depending on the options.




            which shows all variables, shell and environment, without their value or extra info. You will have to echo $VARIABLE_NAME to find the variable value. But at least the list is complete. It belongs to bash, not zsh.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 26 '14 at 19:15

























            answered Dec 26 '14 at 15:36









            MariusMatutiae

            3,31611225




            3,31611225








            • 1




              export has no advantage over set, at least, when it comes to quoting for shell re-entry. And printenv and env are not at all about shell variables, though these do often coincide with environment variables.
              – mikeserv
              Dec 26 '14 at 17:05
















            • 1




              export has no advantage over set, at least, when it comes to quoting for shell re-entry. And printenv and env are not at all about shell variables, though these do often coincide with environment variables.
              – mikeserv
              Dec 26 '14 at 17:05










            1




            1




            export has no advantage over set, at least, when it comes to quoting for shell re-entry. And printenv and env are not at all about shell variables, though these do often coincide with environment variables.
            – mikeserv
            Dec 26 '14 at 17:05






            export has no advantage over set, at least, when it comes to quoting for shell re-entry. And printenv and env are not at all about shell variables, though these do often coincide with environment variables.
            – mikeserv
            Dec 26 '14 at 17:05












            up vote
            3
            down vote













            With zsh, you can use typeset, which gives more information than set, e.g. the type of the variables. You can still filter the output with grep or sed, depending on what you want. Environment variables are marked as exported in the output.






            share|improve this answer

























              up vote
              3
              down vote













              With zsh, you can use typeset, which gives more information than set, e.g. the type of the variables. You can still filter the output with grep or sed, depending on what you want. Environment variables are marked as exported in the output.






              share|improve this answer























                up vote
                3
                down vote










                up vote
                3
                down vote









                With zsh, you can use typeset, which gives more information than set, e.g. the type of the variables. You can still filter the output with grep or sed, depending on what you want. Environment variables are marked as exported in the output.






                share|improve this answer












                With zsh, you can use typeset, which gives more information than set, e.g. the type of the variables. You can still filter the output with grep or sed, depending on what you want. Environment variables are marked as exported in the output.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 26 '14 at 14:37









                vinc17

                8,7591736




                8,7591736






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f176001%2fhow-can-i-list-all-shell-variables%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Morgemoulin

                    Scott Moir

                    Souastre