Why did I get `[three: command not found` from my Bash script? What to do about it? [duplicate]

Clash Royale CLAN TAG#URR8PPP
This question already has an answer here:
Brackets in if condition: why am I getting syntax errors without whitespace?
3 answers
I was testing a Bash script that accepts random arguments and noticed that it would say something like
./Var: line 19: [three: command not found
Here is a minimal working example:
#!/bin/bash
$1 $2 $3
echo "The first argument does $1"
if [$1 >= 2]; then
echo "$1 has 2 words"
else
echo "$1 has unknown amount of words"
fi
#^First
echo "The second argument does $2"
if [$2 >= 2]; then
echo "$2 has 2 words"
else
echo "$2 has unknown amount of words"
fi
#^Second
echo "The third argument does $3"
if [$3 >= 2]; then
echo "$3 has 2 words"
fi
#^Third
But it would continue to run the script, is there a way i can have it run without the "command not found" appearing? Or is this just an issue within my code that is making it do this?
bash shell-script
marked as duplicate by Jeff Schaller, roaima, ilkkachu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 21 at 21:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Brackets in if condition: why am I getting syntax errors without whitespace?
3 answers
I was testing a Bash script that accepts random arguments and noticed that it would say something like
./Var: line 19: [three: command not found
Here is a minimal working example:
#!/bin/bash
$1 $2 $3
echo "The first argument does $1"
if [$1 >= 2]; then
echo "$1 has 2 words"
else
echo "$1 has unknown amount of words"
fi
#^First
echo "The second argument does $2"
if [$2 >= 2]; then
echo "$2 has 2 words"
else
echo "$2 has unknown amount of words"
fi
#^Second
echo "The third argument does $3"
if [$3 >= 2]; then
echo "$3 has 2 words"
fi
#^Third
But it would continue to run the script, is there a way i can have it run without the "command not found" appearing? Or is this just an issue within my code that is making it do this?
bash shell-script
marked as duplicate by Jeff Schaller, roaima, ilkkachu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 21 at 21:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Brackets in if condition: why am I getting syntax errors without whitespace?
3 answers
I was testing a Bash script that accepts random arguments and noticed that it would say something like
./Var: line 19: [three: command not found
Here is a minimal working example:
#!/bin/bash
$1 $2 $3
echo "The first argument does $1"
if [$1 >= 2]; then
echo "$1 has 2 words"
else
echo "$1 has unknown amount of words"
fi
#^First
echo "The second argument does $2"
if [$2 >= 2]; then
echo "$2 has 2 words"
else
echo "$2 has unknown amount of words"
fi
#^Second
echo "The third argument does $3"
if [$3 >= 2]; then
echo "$3 has 2 words"
fi
#^Third
But it would continue to run the script, is there a way i can have it run without the "command not found" appearing? Or is this just an issue within my code that is making it do this?
bash shell-script
This question already has an answer here:
Brackets in if condition: why am I getting syntax errors without whitespace?
3 answers
I was testing a Bash script that accepts random arguments and noticed that it would say something like
./Var: line 19: [three: command not found
Here is a minimal working example:
#!/bin/bash
$1 $2 $3
echo "The first argument does $1"
if [$1 >= 2]; then
echo "$1 has 2 words"
else
echo "$1 has unknown amount of words"
fi
#^First
echo "The second argument does $2"
if [$2 >= 2]; then
echo "$2 has 2 words"
else
echo "$2 has unknown amount of words"
fi
#^Second
echo "The third argument does $3"
if [$3 >= 2]; then
echo "$3 has 2 words"
fi
#^Third
But it would continue to run the script, is there a way i can have it run without the "command not found" appearing? Or is this just an issue within my code that is making it do this?
This question already has an answer here:
Brackets in if condition: why am I getting syntax errors without whitespace?
3 answers
bash shell-script
bash shell-script
edited Jan 21 at 20:40
Kamil Maciorowski
1,6081828
1,6081828
asked Jan 21 at 19:21
RepoSepoRepoSepo
13
13
marked as duplicate by Jeff Schaller, roaima, ilkkachu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 21 at 21:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Jeff Schaller, roaima, ilkkachu
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 21 at 21:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The command you want to use is [ (or test), not [whatever, so it should be (for example)
[ "$3" -ge 2 ]
instead of [$3 >= 2], which generates [three: command not found if $3 is three. Additionally:
- quote your variables;
[doesn't understand>=, it understands-geand other options;>=is a redirection anyway and it didn't get to the command, regardless if the command was[or[three. You now have a file named=.
In Bash [ is a builtin. See help [, help test.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The command you want to use is [ (or test), not [whatever, so it should be (for example)
[ "$3" -ge 2 ]
instead of [$3 >= 2], which generates [three: command not found if $3 is three. Additionally:
- quote your variables;
[doesn't understand>=, it understands-geand other options;>=is a redirection anyway and it didn't get to the command, regardless if the command was[or[three. You now have a file named=.
In Bash [ is a builtin. See help [, help test.
add a comment |
The command you want to use is [ (or test), not [whatever, so it should be (for example)
[ "$3" -ge 2 ]
instead of [$3 >= 2], which generates [three: command not found if $3 is three. Additionally:
- quote your variables;
[doesn't understand>=, it understands-geand other options;>=is a redirection anyway and it didn't get to the command, regardless if the command was[or[three. You now have a file named=.
In Bash [ is a builtin. See help [, help test.
add a comment |
The command you want to use is [ (or test), not [whatever, so it should be (for example)
[ "$3" -ge 2 ]
instead of [$3 >= 2], which generates [three: command not found if $3 is three. Additionally:
- quote your variables;
[doesn't understand>=, it understands-geand other options;>=is a redirection anyway and it didn't get to the command, regardless if the command was[or[three. You now have a file named=.
In Bash [ is a builtin. See help [, help test.
The command you want to use is [ (or test), not [whatever, so it should be (for example)
[ "$3" -ge 2 ]
instead of [$3 >= 2], which generates [three: command not found if $3 is three. Additionally:
- quote your variables;
[doesn't understand>=, it understands-geand other options;>=is a redirection anyway and it didn't get to the command, regardless if the command was[or[three. You now have a file named=.
In Bash [ is a builtin. See help [, help test.
answered Jan 21 at 19:51
Kamil MaciorowskiKamil Maciorowski
1,6081828
1,6081828
add a comment |
add a comment |