What do the arguments '-v' and '-x' mean to bash?
Clash Royale CLAN TAG#URR8PPP
up vote
12
down vote
favorite
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
add a comment |
up vote
12
down vote
favorite
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
add a comment |
up vote
12
down vote
favorite
up vote
12
down vote
favorite
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
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
bash shebang
asked Apr 11 '14 at 12:21
Alex
1,709154270
1,709154270
add a comment |
add a comment |
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.
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 inman
(actually, it'sless
). 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 usingn
for forward search andN
for backward search.
– mtak
Apr 11 '14 at 13:11
Whoops, in fact I was looking attest -x
under CONDITIONAL EXPRESSIONS (the third hit), notset -x
.-x
inman 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 factx
matchesX
...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
add a comment |
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.
add a comment |
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.
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 inman
(actually, it'sless
). 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 usingn
for forward search andN
for backward search.
– mtak
Apr 11 '14 at 13:11
Whoops, in fact I was looking attest -x
under CONDITIONAL EXPRESSIONS (the third hit), notset -x
.-x
inman 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 factx
matchesX
...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
add a comment |
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.
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 inman
(actually, it'sless
). 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 usingn
for forward search andN
for backward search.
– mtak
Apr 11 '14 at 13:11
Whoops, in fact I was looking attest -x
under CONDITIONAL EXPRESSIONS (the third hit), notset -x
.-x
inman 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 factx
matchesX
...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
add a comment |
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.
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.
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 inman
(actually, it'sless
). 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 usingn
for forward search andN
for backward search.
– mtak
Apr 11 '14 at 13:11
Whoops, in fact I was looking attest -x
under CONDITIONAL EXPRESSIONS (the third hit), notset -x
.-x
inman 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 factx
matchesX
...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
add a comment |
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 inman
(actually, it'sless
). 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 usingn
for forward search andN
for backward search.
– mtak
Apr 11 '14 at 13:11
Whoops, in fact I was looking attest -x
under CONDITIONAL EXPRESSIONS (the third hit), notset -x
.-x
inman 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 factx
matchesX
...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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Apr 11 '14 at 14:38
Henk Langeveld
557213
557213
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password