builtin [ , -bash: [: missing `]'
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
while going through learn bash the hard way, I found that [
and test
are both commands and synonyms, and both are builtin.
As it is a builtin it should not give any error for builtin [
, but I am getting -bash: [: missing `]'
,
Can someone explain me the behavior of builtin here.
Thanks in advance.
anupam:Markdown$ which [
/usr/bin/[
anupam:Markdown$ echo $?
0
anupam:Markdown$ which test
/usr/bin/test
anupam:Markdown$ echo $?
0
anupam:Markdown$ builtin test
anupam:Markdown$ echo $?
1
anupam:Markdown$ builtin [
-bash: [: missing `]'
anupam:Markdown$ echo $?
2
anupam:Markdown$
command-line bash
add a comment |Â
up vote
2
down vote
favorite
while going through learn bash the hard way, I found that [
and test
are both commands and synonyms, and both are builtin.
As it is a builtin it should not give any error for builtin [
, but I am getting -bash: [: missing `]'
,
Can someone explain me the behavior of builtin here.
Thanks in advance.
anupam:Markdown$ which [
/usr/bin/[
anupam:Markdown$ echo $?
0
anupam:Markdown$ which test
/usr/bin/test
anupam:Markdown$ echo $?
0
anupam:Markdown$ builtin test
anupam:Markdown$ echo $?
1
anupam:Markdown$ builtin [
-bash: [: missing `]'
anupam:Markdown$ echo $?
2
anupam:Markdown$
command-line bash
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
while going through learn bash the hard way, I found that [
and test
are both commands and synonyms, and both are builtin.
As it is a builtin it should not give any error for builtin [
, but I am getting -bash: [: missing `]'
,
Can someone explain me the behavior of builtin here.
Thanks in advance.
anupam:Markdown$ which [
/usr/bin/[
anupam:Markdown$ echo $?
0
anupam:Markdown$ which test
/usr/bin/test
anupam:Markdown$ echo $?
0
anupam:Markdown$ builtin test
anupam:Markdown$ echo $?
1
anupam:Markdown$ builtin [
-bash: [: missing `]'
anupam:Markdown$ echo $?
2
anupam:Markdown$
command-line bash
while going through learn bash the hard way, I found that [
and test
are both commands and synonyms, and both are builtin.
As it is a builtin it should not give any error for builtin [
, but I am getting -bash: [: missing `]'
,
Can someone explain me the behavior of builtin here.
Thanks in advance.
anupam:Markdown$ which [
/usr/bin/[
anupam:Markdown$ echo $?
0
anupam:Markdown$ which test
/usr/bin/test
anupam:Markdown$ echo $?
0
anupam:Markdown$ builtin test
anupam:Markdown$ echo $?
1
anupam:Markdown$ builtin [
-bash: [: missing `]'
anupam:Markdown$ echo $?
2
anupam:Markdown$
command-line bash
command-line bash
edited 15 mins ago
Melebius
3,95051736
3,95051736
asked 29 mins ago


jazzz
59631336
59631336
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
The [
version of the command requires ]
as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “blockâ€Â, so commands look this way:
if [ $1 -eq 2 ]; then
instead of
if [ $1 -eq 2; then
The test
version does not require the final ]
but accepts it. See help [
:
$ help [
[: [ arg... ]
Evaluate conditional expression.
This is a synonym for the "test" builtin, but the last argument must
be a literal `]', to match the opening `['.
Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
– jazzz
15 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
The [
version of the command requires ]
as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “blockâ€Â, so commands look this way:
if [ $1 -eq 2 ]; then
instead of
if [ $1 -eq 2; then
The test
version does not require the final ]
but accepts it. See help [
:
$ help [
[: [ arg... ]
Evaluate conditional expression.
This is a synonym for the "test" builtin, but the last argument must
be a literal `]', to match the opening `['.
Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
– jazzz
15 mins ago
add a comment |Â
up vote
3
down vote
The [
version of the command requires ]
as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “blockâ€Â, so commands look this way:
if [ $1 -eq 2 ]; then
instead of
if [ $1 -eq 2; then
The test
version does not require the final ]
but accepts it. See help [
:
$ help [
[: [ arg... ]
Evaluate conditional expression.
This is a synonym for the "test" builtin, but the last argument must
be a literal `]', to match the opening `['.
Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
– jazzz
15 mins ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
The [
version of the command requires ]
as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “blockâ€Â, so commands look this way:
if [ $1 -eq 2 ]; then
instead of
if [ $1 -eq 2; then
The test
version does not require the final ]
but accepts it. See help [
:
$ help [
[: [ arg... ]
Evaluate conditional expression.
This is a synonym for the "test" builtin, but the last argument must
be a literal `]', to match the opening `['.
The [
version of the command requires ]
as the mandatory last parameter (so it must be preceded by a space). It’s just a formal, syntactic thing to force users to close the bracketed “blockâ€Â, so commands look this way:
if [ $1 -eq 2 ]; then
instead of
if [ $1 -eq 2; then
The test
version does not require the final ]
but accepts it. See help [
:
$ help [
[: [ arg... ]
Evaluate conditional expression.
This is a synonym for the "test" builtin, but the last argument must
be a literal `]', to match the opening `['.
edited 17 mins ago
muru
131k19278474
131k19278474
answered 22 mins ago
Melebius
3,95051736
3,95051736
Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
– jazzz
15 mins ago
add a comment |Â
Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
– jazzz
15 mins ago
Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
– jazzz
15 mins ago
Thanks @Melebius , so I checked for ` builtin [ ] ` and it worked .
– jazzz
15 mins ago
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%2faskubuntu.com%2fquestions%2f1083854%2fbuiltin-bash-missing%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