What do the arguments '-v' and '-x' mean to bash?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
12
down vote

favorite
3












I have seen a couple of shell scripts with the following shebang:



#!/bin/bash -x -v 


However, man bash does not explain what these arguments -x and -v stand for, if they are belong to bash at all.



So what do those -x and -v (and other possible arguments) mean?










share|improve this question

























    up vote
    12
    down vote

    favorite
    3












    I have seen a couple of shell scripts with the following shebang:



    #!/bin/bash -x -v 


    However, man bash does not explain what these arguments -x and -v stand for, if they are belong to bash at all.



    So what do those -x and -v (and other possible arguments) mean?










    share|improve this question























      up vote
      12
      down vote

      favorite
      3









      up vote
      12
      down vote

      favorite
      3






      3





      I have seen a couple of shell scripts with the following shebang:



      #!/bin/bash -x -v 


      However, man bash does not explain what these arguments -x and -v stand for, if they are belong to bash at all.



      So what do those -x and -v (and other possible arguments) mean?










      share|improve this question













      I have seen a couple of shell scripts with the following shebang:



      #!/bin/bash -x -v 


      However, man bash does not explain what these arguments -x and -v stand for, if they are belong to bash at all.



      So what do those -x and -v (and other possible arguments) mean?







      bash shebang






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 11 '14 at 12:21









      Alex

      1,709154270




      1,709154270




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          21
          down vote













          From man bash (yes, it's a big man page, usually Google search is faster):




          -x After expanding each simple command, for command, case command, select command, or arithmetic for command, display the expanded value of PS4, followed by the command and its expanded arguments or associated word list.




          Effectively: when you run a script, it will show all actions done in that script. So all ifs, loops and commands run. Very useful for debugging.




          -v Print shell input lines as they are read. When a script is run, it will print the entire script as it reads the file. When you use the shell interactively, it will show each command after you press enter.




          The quotes above are from the explanation of the set builtin command in the man bash, which also explains that the options for set can also be passed as arguments (on the shebang line):




          The options are off by default unless otherwise noted. Using +
          rather than - causes these options to be turned off. The
          options can also be specified as arguments to an invocation of
          the shell.
          The current set of options may be found in $-. The
          return status is always true unless an invalid option is encountered.







          share|improve this answer






















          • Ok, so it is a simple argument to bash, and I just might have a different version without these arguments?
            – Alex
            Apr 11 '14 at 12:26










          • If you are talking about bash: I think all bash releases of the past decade will support these arguments. If you are talking about the man page: it's huge and you need to know what you're looking for, but it is there (at least on Ubuntu 13.04). Usually a Google search is quicker.
            – mtak
            Apr 11 '14 at 12:28







          • 6




            +1 "Google search is faster" -> /-x a couple of times will get you there in man (actually, it's less). You can repeat the last search with / + up arrow, but you have to page down to get any current search hit off the screen (/ is forward search, ? is backward).
            – goldilocks
            Apr 11 '14 at 12:54







          • 2




            @TAFKA'goldilocks' I guess it depends on your distro. In the Ubuntu 13.04 bash manual page the 43th hit is the right one. It's easier to search for the next hit in less by using n for forward search and N for backward search.
            – mtak
            Apr 11 '14 at 13:11










          • Whoops, in fact I was looking at test -x under CONDITIONAL EXPRESSIONS (the third hit), not set -x. -x in man bash is a pretty bad case so getting more specific helps: If you use /^s+-xb, (= start of line + whitespace + -x + word boundary) you get to the right one in 5 hits...it would have been 4 but for the fact x matches X...which leads me to a question I've been meaning to ask. Anyway, w/ most man pages the ^s+-xb pattern should work first try for switches.
            – goldilocks
            Apr 11 '14 at 13:34


















          up vote
          2
          down vote













          The bash man page does hint that these options are explained further down, actually, but it's easily overlooked.



          Therefore your problem should actually read: The OPTIONS section of the bash man page is incomplete. The answer would be to either duplicate them, or highlight the first section of the OPTIONS section:



          OPTIONS
          All of the single-character shell options documented in the descrip‐
          tion of the set builtin command can be used as options when the shell
          is invoked. [ ... ]


          Finally, to make this complete: they are standard options for any POSIX shell for showing the code of the script when read (-v) and when run (-x).
          Output will appear on stderr.






          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%2f124272%2fwhat-do-the-arguments-v-and-x-mean-to-bash%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            21
            down vote













            From man bash (yes, it's a big man page, usually Google search is faster):




            -x After expanding each simple command, for command, case command, select command, or arithmetic for command, display the expanded value of PS4, followed by the command and its expanded arguments or associated word list.




            Effectively: when you run a script, it will show all actions done in that script. So all ifs, loops and commands run. Very useful for debugging.




            -v Print shell input lines as they are read. When a script is run, it will print the entire script as it reads the file. When you use the shell interactively, it will show each command after you press enter.




            The quotes above are from the explanation of the set builtin command in the man bash, which also explains that the options for set can also be passed as arguments (on the shebang line):




            The options are off by default unless otherwise noted. Using +
            rather than - causes these options to be turned off. The
            options can also be specified as arguments to an invocation of
            the shell.
            The current set of options may be found in $-. The
            return status is always true unless an invalid option is encountered.







            share|improve this answer






















            • Ok, so it is a simple argument to bash, and I just might have a different version without these arguments?
              – Alex
              Apr 11 '14 at 12:26










            • If you are talking about bash: I think all bash releases of the past decade will support these arguments. If you are talking about the man page: it's huge and you need to know what you're looking for, but it is there (at least on Ubuntu 13.04). Usually a Google search is quicker.
              – mtak
              Apr 11 '14 at 12:28







            • 6




              +1 "Google search is faster" -> /-x a couple of times will get you there in man (actually, it's less). You can repeat the last search with / + up arrow, but you have to page down to get any current search hit off the screen (/ is forward search, ? is backward).
              – goldilocks
              Apr 11 '14 at 12:54







            • 2




              @TAFKA'goldilocks' I guess it depends on your distro. In the Ubuntu 13.04 bash manual page the 43th hit is the right one. It's easier to search for the next hit in less by using n for forward search and N for backward search.
              – mtak
              Apr 11 '14 at 13:11










            • Whoops, in fact I was looking at test -x under CONDITIONAL EXPRESSIONS (the third hit), not set -x. -x in man bash is a pretty bad case so getting more specific helps: If you use /^s+-xb, (= start of line + whitespace + -x + word boundary) you get to the right one in 5 hits...it would have been 4 but for the fact x matches X...which leads me to a question I've been meaning to ask. Anyway, w/ most man pages the ^s+-xb pattern should work first try for switches.
              – goldilocks
              Apr 11 '14 at 13:34















            up vote
            21
            down vote













            From man bash (yes, it's a big man page, usually Google search is faster):




            -x After expanding each simple command, for command, case command, select command, or arithmetic for command, display the expanded value of PS4, followed by the command and its expanded arguments or associated word list.




            Effectively: when you run a script, it will show all actions done in that script. So all ifs, loops and commands run. Very useful for debugging.




            -v Print shell input lines as they are read. When a script is run, it will print the entire script as it reads the file. When you use the shell interactively, it will show each command after you press enter.




            The quotes above are from the explanation of the set builtin command in the man bash, which also explains that the options for set can also be passed as arguments (on the shebang line):




            The options are off by default unless otherwise noted. Using +
            rather than - causes these options to be turned off. The
            options can also be specified as arguments to an invocation of
            the shell.
            The current set of options may be found in $-. The
            return status is always true unless an invalid option is encountered.







            share|improve this answer






















            • Ok, so it is a simple argument to bash, and I just might have a different version without these arguments?
              – Alex
              Apr 11 '14 at 12:26










            • If you are talking about bash: I think all bash releases of the past decade will support these arguments. If you are talking about the man page: it's huge and you need to know what you're looking for, but it is there (at least on Ubuntu 13.04). Usually a Google search is quicker.
              – mtak
              Apr 11 '14 at 12:28







            • 6




              +1 "Google search is faster" -> /-x a couple of times will get you there in man (actually, it's less). You can repeat the last search with / + up arrow, but you have to page down to get any current search hit off the screen (/ is forward search, ? is backward).
              – goldilocks
              Apr 11 '14 at 12:54







            • 2




              @TAFKA'goldilocks' I guess it depends on your distro. In the Ubuntu 13.04 bash manual page the 43th hit is the right one. It's easier to search for the next hit in less by using n for forward search and N for backward search.
              – mtak
              Apr 11 '14 at 13:11










            • Whoops, in fact I was looking at test -x under CONDITIONAL EXPRESSIONS (the third hit), not set -x. -x in man bash is a pretty bad case so getting more specific helps: If you use /^s+-xb, (= start of line + whitespace + -x + word boundary) you get to the right one in 5 hits...it would have been 4 but for the fact x matches X...which leads me to a question I've been meaning to ask. Anyway, w/ most man pages the ^s+-xb pattern should work first try for switches.
              – goldilocks
              Apr 11 '14 at 13:34













            up vote
            21
            down vote










            up vote
            21
            down vote









            From man bash (yes, it's a big man page, usually Google search is faster):




            -x After expanding each simple command, for command, case command, select command, or arithmetic for command, display the expanded value of PS4, followed by the command and its expanded arguments or associated word list.




            Effectively: when you run a script, it will show all actions done in that script. So all ifs, loops and commands run. Very useful for debugging.




            -v Print shell input lines as they are read. When a script is run, it will print the entire script as it reads the file. When you use the shell interactively, it will show each command after you press enter.




            The quotes above are from the explanation of the set builtin command in the man bash, which also explains that the options for set can also be passed as arguments (on the shebang line):




            The options are off by default unless otherwise noted. Using +
            rather than - causes these options to be turned off. The
            options can also be specified as arguments to an invocation of
            the shell.
            The current set of options may be found in $-. The
            return status is always true unless an invalid option is encountered.







            share|improve this answer














            From man bash (yes, it's a big man page, usually Google search is faster):




            -x After expanding each simple command, for command, case command, select command, or arithmetic for command, display the expanded value of PS4, followed by the command and its expanded arguments or associated word list.




            Effectively: when you run a script, it will show all actions done in that script. So all ifs, loops and commands run. Very useful for debugging.




            -v Print shell input lines as they are read. When a script is run, it will print the entire script as it reads the file. When you use the shell interactively, it will show each command after you press enter.




            The quotes above are from the explanation of the set builtin command in the man bash, which also explains that the options for set can also be passed as arguments (on the shebang line):




            The options are off by default unless otherwise noted. Using +
            rather than - causes these options to be turned off. The
            options can also be specified as arguments to an invocation of
            the shell.
            The current set of options may be found in $-. The
            return status is always true unless an invalid option is encountered.








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 11 '14 at 14:49









            Gilles

            519k12510371567




            519k12510371567










            answered Apr 11 '14 at 12:25









            mtak

            984511




            984511











            • Ok, so it is a simple argument to bash, and I just might have a different version without these arguments?
              – Alex
              Apr 11 '14 at 12:26










            • If you are talking about bash: I think all bash releases of the past decade will support these arguments. If you are talking about the man page: it's huge and you need to know what you're looking for, but it is there (at least on Ubuntu 13.04). Usually a Google search is quicker.
              – mtak
              Apr 11 '14 at 12:28







            • 6




              +1 "Google search is faster" -> /-x a couple of times will get you there in man (actually, it's less). You can repeat the last search with / + up arrow, but you have to page down to get any current search hit off the screen (/ is forward search, ? is backward).
              – goldilocks
              Apr 11 '14 at 12:54







            • 2




              @TAFKA'goldilocks' I guess it depends on your distro. In the Ubuntu 13.04 bash manual page the 43th hit is the right one. It's easier to search for the next hit in less by using n for forward search and N for backward search.
              – mtak
              Apr 11 '14 at 13:11










            • Whoops, in fact I was looking at test -x under CONDITIONAL EXPRESSIONS (the third hit), not set -x. -x in man bash is a pretty bad case so getting more specific helps: If you use /^s+-xb, (= start of line + whitespace + -x + word boundary) you get to the right one in 5 hits...it would have been 4 but for the fact x matches X...which leads me to a question I've been meaning to ask. Anyway, w/ most man pages the ^s+-xb pattern should work first try for switches.
              – goldilocks
              Apr 11 '14 at 13:34

















            • Ok, so it is a simple argument to bash, and I just might have a different version without these arguments?
              – Alex
              Apr 11 '14 at 12:26










            • If you are talking about bash: I think all bash releases of the past decade will support these arguments. If you are talking about the man page: it's huge and you need to know what you're looking for, but it is there (at least on Ubuntu 13.04). Usually a Google search is quicker.
              – mtak
              Apr 11 '14 at 12:28







            • 6




              +1 "Google search is faster" -> /-x a couple of times will get you there in man (actually, it's less). You can repeat the last search with / + up arrow, but you have to page down to get any current search hit off the screen (/ is forward search, ? is backward).
              – goldilocks
              Apr 11 '14 at 12:54







            • 2




              @TAFKA'goldilocks' I guess it depends on your distro. In the Ubuntu 13.04 bash manual page the 43th hit is the right one. It's easier to search for the next hit in less by using n for forward search and N for backward search.
              – mtak
              Apr 11 '14 at 13:11










            • Whoops, in fact I was looking at test -x under CONDITIONAL EXPRESSIONS (the third hit), not set -x. -x in man bash is a pretty bad case so getting more specific helps: If you use /^s+-xb, (= start of line + whitespace + -x + word boundary) you get to the right one in 5 hits...it would have been 4 but for the fact x matches X...which leads me to a question I've been meaning to ask. Anyway, w/ most man pages the ^s+-xb pattern should work first try for switches.
              – goldilocks
              Apr 11 '14 at 13:34
















            Ok, so it is a simple argument to bash, and I just might have a different version without these arguments?
            – Alex
            Apr 11 '14 at 12:26




            Ok, so it is a simple argument to bash, and I just might have a different version without these arguments?
            – Alex
            Apr 11 '14 at 12:26












            If you are talking about bash: I think all bash releases of the past decade will support these arguments. If you are talking about the man page: it's huge and you need to know what you're looking for, but it is there (at least on Ubuntu 13.04). Usually a Google search is quicker.
            – mtak
            Apr 11 '14 at 12:28





            If you are talking about bash: I think all bash releases of the past decade will support these arguments. If you are talking about the man page: it's huge and you need to know what you're looking for, but it is there (at least on Ubuntu 13.04). Usually a Google search is quicker.
            – mtak
            Apr 11 '14 at 12:28





            6




            6




            +1 "Google search is faster" -> /-x a couple of times will get you there in man (actually, it's less). You can repeat the last search with / + up arrow, but you have to page down to get any current search hit off the screen (/ is forward search, ? is backward).
            – goldilocks
            Apr 11 '14 at 12:54





            +1 "Google search is faster" -> /-x a couple of times will get you there in man (actually, it's less). You can repeat the last search with / + up arrow, but you have to page down to get any current search hit off the screen (/ is forward search, ? is backward).
            – goldilocks
            Apr 11 '14 at 12:54





            2




            2




            @TAFKA'goldilocks' I guess it depends on your distro. In the Ubuntu 13.04 bash manual page the 43th hit is the right one. It's easier to search for the next hit in less by using n for forward search and N for backward search.
            – mtak
            Apr 11 '14 at 13:11




            @TAFKA'goldilocks' I guess it depends on your distro. In the Ubuntu 13.04 bash manual page the 43th hit is the right one. It's easier to search for the next hit in less by using n for forward search and N for backward search.
            – mtak
            Apr 11 '14 at 13:11












            Whoops, in fact I was looking at test -x under CONDITIONAL EXPRESSIONS (the third hit), not set -x. -x in man bash is a pretty bad case so getting more specific helps: If you use /^s+-xb, (= start of line + whitespace + -x + word boundary) you get to the right one in 5 hits...it would have been 4 but for the fact x matches X...which leads me to a question I've been meaning to ask. Anyway, w/ most man pages the ^s+-xb pattern should work first try for switches.
            – goldilocks
            Apr 11 '14 at 13:34





            Whoops, in fact I was looking at test -x under CONDITIONAL EXPRESSIONS (the third hit), not set -x. -x in man bash is a pretty bad case so getting more specific helps: If you use /^s+-xb, (= start of line + whitespace + -x + word boundary) you get to the right one in 5 hits...it would have been 4 but for the fact x matches X...which leads me to a question I've been meaning to ask. Anyway, w/ most man pages the ^s+-xb pattern should work first try for switches.
            – goldilocks
            Apr 11 '14 at 13:34













            up vote
            2
            down vote













            The bash man page does hint that these options are explained further down, actually, but it's easily overlooked.



            Therefore your problem should actually read: The OPTIONS section of the bash man page is incomplete. The answer would be to either duplicate them, or highlight the first section of the OPTIONS section:



            OPTIONS
            All of the single-character shell options documented in the descrip‐
            tion of the set builtin command can be used as options when the shell
            is invoked. [ ... ]


            Finally, to make this complete: they are standard options for any POSIX shell for showing the code of the script when read (-v) and when run (-x).
            Output will appear on stderr.






            share|improve this answer
























              up vote
              2
              down vote













              The bash man page does hint that these options are explained further down, actually, but it's easily overlooked.



              Therefore your problem should actually read: The OPTIONS section of the bash man page is incomplete. The answer would be to either duplicate them, or highlight the first section of the OPTIONS section:



              OPTIONS
              All of the single-character shell options documented in the descrip‐
              tion of the set builtin command can be used as options when the shell
              is invoked. [ ... ]


              Finally, to make this complete: they are standard options for any POSIX shell for showing the code of the script when read (-v) and when run (-x).
              Output will appear on stderr.






              share|improve this answer






















                up vote
                2
                down vote










                up vote
                2
                down vote









                The bash man page does hint that these options are explained further down, actually, but it's easily overlooked.



                Therefore your problem should actually read: The OPTIONS section of the bash man page is incomplete. The answer would be to either duplicate them, or highlight the first section of the OPTIONS section:



                OPTIONS
                All of the single-character shell options documented in the descrip‐
                tion of the set builtin command can be used as options when the shell
                is invoked. [ ... ]


                Finally, to make this complete: they are standard options for any POSIX shell for showing the code of the script when read (-v) and when run (-x).
                Output will appear on stderr.






                share|improve this answer












                The bash man page does hint that these options are explained further down, actually, but it's easily overlooked.



                Therefore your problem should actually read: The OPTIONS section of the bash man page is incomplete. The answer would be to either duplicate them, or highlight the first section of the OPTIONS section:



                OPTIONS
                All of the single-character shell options documented in the descrip‐
                tion of the set builtin command can be used as options when the shell
                is invoked. [ ... ]


                Finally, to make this complete: they are standard options for any POSIX shell for showing the code of the script when read (-v) and when run (-x).
                Output will appear on stderr.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 11 '14 at 14:38









                Henk Langeveld

                557213




                557213



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f124272%2fwhat-do-the-arguments-v-and-x-mean-to-bash%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay