elif condition in an if statement











up vote
1
down vote

favorite












I have this variables



start=$1;
end=$2;
sn=${#start}
en=${#end}


and this if :



if ( [ $# -eq 2 ] )
then
elif ( [ $sn -ne 3 ] && [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g') " ] );
then
echo "Incorrect format"
exit 1
elif ( [ $en -ne 3 ] && [ -n "$(printf '%sn' "$end" | sed 's/[0-9]//g') " ] );
then
echo "Incorrect format"
exit 1
else
echo "Correct format"
exit 1
fi


and I get unexpected at the first elif , I want to check the arguments provided by the user and they have to be made by only 3 digits .










share|improve this question









New contributor




bboy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 3




    another plug for shellcheck.net here
    – Jeff Schaller
    2 days ago






  • 1




    What is the input that causes your unexpected results, what results are you actually getting, and what results do you want?
    – Jesse_b
    2 days ago












  • I want to have the incorrect format echo on the screen if the provided variables are not 2 digits like 11 , 12 , 55 and echo that the format is correct if there are only 2 digits provided for both arguments .
    – bboy
    2 days ago






  • 1




    You have said you want them to be 3 digits in your question and that you want them to be 2 digits in a comment. Please clarify.
    – Jesse_b
    2 days ago










  • sorry indeed is about 3 digits , the number of arguments is 2
    – bboy
    2 days ago















up vote
1
down vote

favorite












I have this variables



start=$1;
end=$2;
sn=${#start}
en=${#end}


and this if :



if ( [ $# -eq 2 ] )
then
elif ( [ $sn -ne 3 ] && [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g') " ] );
then
echo "Incorrect format"
exit 1
elif ( [ $en -ne 3 ] && [ -n "$(printf '%sn' "$end" | sed 's/[0-9]//g') " ] );
then
echo "Incorrect format"
exit 1
else
echo "Correct format"
exit 1
fi


and I get unexpected at the first elif , I want to check the arguments provided by the user and they have to be made by only 3 digits .










share|improve this question









New contributor




bboy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 3




    another plug for shellcheck.net here
    – Jeff Schaller
    2 days ago






  • 1




    What is the input that causes your unexpected results, what results are you actually getting, and what results do you want?
    – Jesse_b
    2 days ago












  • I want to have the incorrect format echo on the screen if the provided variables are not 2 digits like 11 , 12 , 55 and echo that the format is correct if there are only 2 digits provided for both arguments .
    – bboy
    2 days ago






  • 1




    You have said you want them to be 3 digits in your question and that you want them to be 2 digits in a comment. Please clarify.
    – Jesse_b
    2 days ago










  • sorry indeed is about 3 digits , the number of arguments is 2
    – bboy
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have this variables



start=$1;
end=$2;
sn=${#start}
en=${#end}


and this if :



if ( [ $# -eq 2 ] )
then
elif ( [ $sn -ne 3 ] && [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g') " ] );
then
echo "Incorrect format"
exit 1
elif ( [ $en -ne 3 ] && [ -n "$(printf '%sn' "$end" | sed 's/[0-9]//g') " ] );
then
echo "Incorrect format"
exit 1
else
echo "Correct format"
exit 1
fi


and I get unexpected at the first elif , I want to check the arguments provided by the user and they have to be made by only 3 digits .










share|improve this question









New contributor




bboy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have this variables



start=$1;
end=$2;
sn=${#start}
en=${#end}


and this if :



if ( [ $# -eq 2 ] )
then
elif ( [ $sn -ne 3 ] && [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g') " ] );
then
echo "Incorrect format"
exit 1
elif ( [ $en -ne 3 ] && [ -n "$(printf '%sn' "$end" | sed 's/[0-9]//g') " ] );
then
echo "Incorrect format"
exit 1
else
echo "Correct format"
exit 1
fi


and I get unexpected at the first elif , I want to check the arguments provided by the user and they have to be made by only 3 digits .







bash sed scripting variable






share|improve this question









New contributor




bboy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




bboy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Jesse_b

11.5k23063




11.5k23063






New contributor




bboy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









bboy

274




274




New contributor




bboy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





bboy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






bboy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 3




    another plug for shellcheck.net here
    – Jeff Schaller
    2 days ago






  • 1




    What is the input that causes your unexpected results, what results are you actually getting, and what results do you want?
    – Jesse_b
    2 days ago












  • I want to have the incorrect format echo on the screen if the provided variables are not 2 digits like 11 , 12 , 55 and echo that the format is correct if there are only 2 digits provided for both arguments .
    – bboy
    2 days ago






  • 1




    You have said you want them to be 3 digits in your question and that you want them to be 2 digits in a comment. Please clarify.
    – Jesse_b
    2 days ago










  • sorry indeed is about 3 digits , the number of arguments is 2
    – bboy
    2 days ago














  • 3




    another plug for shellcheck.net here
    – Jeff Schaller
    2 days ago






  • 1




    What is the input that causes your unexpected results, what results are you actually getting, and what results do you want?
    – Jesse_b
    2 days ago












  • I want to have the incorrect format echo on the screen if the provided variables are not 2 digits like 11 , 12 , 55 and echo that the format is correct if there are only 2 digits provided for both arguments .
    – bboy
    2 days ago






  • 1




    You have said you want them to be 3 digits in your question and that you want them to be 2 digits in a comment. Please clarify.
    – Jesse_b
    2 days ago










  • sorry indeed is about 3 digits , the number of arguments is 2
    – bboy
    2 days ago








3




3




another plug for shellcheck.net here
– Jeff Schaller
2 days ago




another plug for shellcheck.net here
– Jeff Schaller
2 days ago




1




1




What is the input that causes your unexpected results, what results are you actually getting, and what results do you want?
– Jesse_b
2 days ago






What is the input that causes your unexpected results, what results are you actually getting, and what results do you want?
– Jesse_b
2 days ago














I want to have the incorrect format echo on the screen if the provided variables are not 2 digits like 11 , 12 , 55 and echo that the format is correct if there are only 2 digits provided for both arguments .
– bboy
2 days ago




I want to have the incorrect format echo on the screen if the provided variables are not 2 digits like 11 , 12 , 55 and echo that the format is correct if there are only 2 digits provided for both arguments .
– bboy
2 days ago




1




1




You have said you want them to be 3 digits in your question and that you want them to be 2 digits in a comment. Please clarify.
– Jesse_b
2 days ago




You have said you want them to be 3 digits in your question and that you want them to be 2 digits in a comment. Please clarify.
– Jesse_b
2 days ago












sorry indeed is about 3 digits , the number of arguments is 2
– bboy
2 days ago




sorry indeed is about 3 digits , the number of arguments is 2
– bboy
2 days ago










2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










if ( [ $# -eq 2 ] )
then
elif


As Jeff's answer says, the first if condition is missing the part with the commands. The error messages given by Bash and Dash are a bit vague, it seems like they come directly from the parser, and they haven't bothered to add a more user-friendly message there.



If you don't want to do anything inside a branch, you'll still need to add some command there. I'd suggest true, which doesn't do anything.



Fixing that, shellcheck.net gives a couple of more observations:



if ( [ $# -eq 2 ] )
^-- SC2233: Remove superfluous (..) around condition.


The parenthesis start a subshell, which is not necessary here (and involves extra overhead, like forking a subprocess in Bash).



... [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g') " ] 
>> ^--
SC2157: Argument to -n is always true due to literal strings.


You've quoted the command substitution, good! But you have an extra space there in the end. Whatever the command substitution outputs, the argument to -n will never be empty, because of that space.



(It also notes about quoting $sn and $en, which would be the careful thing to do, but isn't really necessary if you know IFS doesn't contain any digits.)





That said, I'm not sure the conditions still are quite right. You say:




I want to check the arguments provided by the user and they have to be made by only 3 digits .




But note that the test below catches only the case where sn is not three, and in addition there are other characters than numbers, i.e. it passes abc and 1234, and only rejects, say abcd. You want an or condition, ||, instead of and.



if [ $sn -ne 3 ] && [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g')" ]; then
echo reject


Or you could just use case and a pattern match:



case "$start" in
[0-9][0-9][0-9]) echo "'$start' is ok";;
*) echo "'$start' is invalid"; exit 1;;
esac





share|improve this answer























  • Thank you very much , using the case statement helped !
    – bboy
    2 days ago






  • 1




    Or, with bash, if [[ $start != [0-9][0-9][0-9] ]]; then die; fi -- within double brackets, the == and != operators are pattern matching
    – glenn jackman
    2 days ago




















up vote
3
down vote













You don't have any statements in the "true" case of your first if:



if ( [ $# -eq 2 ] )

then
## <-- HERE
elif ...


Quoting the bash manual:




The syntax of the if command is:



if test-commands; then
consequent-commands;
[elif more-test-commands; then
more-consequents;]
[else alternate-consequents;]
fi



Where the important bit is the consequent-commands.






share|improve this answer





















  • After updating the statement no check is done on the provided variables .
    – bboy
    2 days ago






  • 1




    @bboy: That's because you likely don't want to check if there are two arguments, you probably want to check if there is not two arguments.
    – Jesse_b
    2 days ago






  • 1




    Specifically, when using if, you have to do something if the test returns something truthy. If you only want to act when the result is falsy, you must either add a no-op to the consequent-commands, or flip the logic of the test: Either if test; then :; else thing; fi or if ! test; then thing; fi. The same holds true for elif.
    – DopeGhoti
    2 days ago











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
});


}
});






bboy is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484739%2felif-condition-in-an-if-statement%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










if ( [ $# -eq 2 ] )
then
elif


As Jeff's answer says, the first if condition is missing the part with the commands. The error messages given by Bash and Dash are a bit vague, it seems like they come directly from the parser, and they haven't bothered to add a more user-friendly message there.



If you don't want to do anything inside a branch, you'll still need to add some command there. I'd suggest true, which doesn't do anything.



Fixing that, shellcheck.net gives a couple of more observations:



if ( [ $# -eq 2 ] )
^-- SC2233: Remove superfluous (..) around condition.


The parenthesis start a subshell, which is not necessary here (and involves extra overhead, like forking a subprocess in Bash).



... [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g') " ] 
>> ^--
SC2157: Argument to -n is always true due to literal strings.


You've quoted the command substitution, good! But you have an extra space there in the end. Whatever the command substitution outputs, the argument to -n will never be empty, because of that space.



(It also notes about quoting $sn and $en, which would be the careful thing to do, but isn't really necessary if you know IFS doesn't contain any digits.)





That said, I'm not sure the conditions still are quite right. You say:




I want to check the arguments provided by the user and they have to be made by only 3 digits .




But note that the test below catches only the case where sn is not three, and in addition there are other characters than numbers, i.e. it passes abc and 1234, and only rejects, say abcd. You want an or condition, ||, instead of and.



if [ $sn -ne 3 ] && [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g')" ]; then
echo reject


Or you could just use case and a pattern match:



case "$start" in
[0-9][0-9][0-9]) echo "'$start' is ok";;
*) echo "'$start' is invalid"; exit 1;;
esac





share|improve this answer























  • Thank you very much , using the case statement helped !
    – bboy
    2 days ago






  • 1




    Or, with bash, if [[ $start != [0-9][0-9][0-9] ]]; then die; fi -- within double brackets, the == and != operators are pattern matching
    – glenn jackman
    2 days ago

















up vote
3
down vote



accepted










if ( [ $# -eq 2 ] )
then
elif


As Jeff's answer says, the first if condition is missing the part with the commands. The error messages given by Bash and Dash are a bit vague, it seems like they come directly from the parser, and they haven't bothered to add a more user-friendly message there.



If you don't want to do anything inside a branch, you'll still need to add some command there. I'd suggest true, which doesn't do anything.



Fixing that, shellcheck.net gives a couple of more observations:



if ( [ $# -eq 2 ] )
^-- SC2233: Remove superfluous (..) around condition.


The parenthesis start a subshell, which is not necessary here (and involves extra overhead, like forking a subprocess in Bash).



... [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g') " ] 
>> ^--
SC2157: Argument to -n is always true due to literal strings.


You've quoted the command substitution, good! But you have an extra space there in the end. Whatever the command substitution outputs, the argument to -n will never be empty, because of that space.



(It also notes about quoting $sn and $en, which would be the careful thing to do, but isn't really necessary if you know IFS doesn't contain any digits.)





That said, I'm not sure the conditions still are quite right. You say:




I want to check the arguments provided by the user and they have to be made by only 3 digits .




But note that the test below catches only the case where sn is not three, and in addition there are other characters than numbers, i.e. it passes abc and 1234, and only rejects, say abcd. You want an or condition, ||, instead of and.



if [ $sn -ne 3 ] && [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g')" ]; then
echo reject


Or you could just use case and a pattern match:



case "$start" in
[0-9][0-9][0-9]) echo "'$start' is ok";;
*) echo "'$start' is invalid"; exit 1;;
esac





share|improve this answer























  • Thank you very much , using the case statement helped !
    – bboy
    2 days ago






  • 1




    Or, with bash, if [[ $start != [0-9][0-9][0-9] ]]; then die; fi -- within double brackets, the == and != operators are pattern matching
    – glenn jackman
    2 days ago















up vote
3
down vote



accepted







up vote
3
down vote



accepted






if ( [ $# -eq 2 ] )
then
elif


As Jeff's answer says, the first if condition is missing the part with the commands. The error messages given by Bash and Dash are a bit vague, it seems like they come directly from the parser, and they haven't bothered to add a more user-friendly message there.



If you don't want to do anything inside a branch, you'll still need to add some command there. I'd suggest true, which doesn't do anything.



Fixing that, shellcheck.net gives a couple of more observations:



if ( [ $# -eq 2 ] )
^-- SC2233: Remove superfluous (..) around condition.


The parenthesis start a subshell, which is not necessary here (and involves extra overhead, like forking a subprocess in Bash).



... [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g') " ] 
>> ^--
SC2157: Argument to -n is always true due to literal strings.


You've quoted the command substitution, good! But you have an extra space there in the end. Whatever the command substitution outputs, the argument to -n will never be empty, because of that space.



(It also notes about quoting $sn and $en, which would be the careful thing to do, but isn't really necessary if you know IFS doesn't contain any digits.)





That said, I'm not sure the conditions still are quite right. You say:




I want to check the arguments provided by the user and they have to be made by only 3 digits .




But note that the test below catches only the case where sn is not three, and in addition there are other characters than numbers, i.e. it passes abc and 1234, and only rejects, say abcd. You want an or condition, ||, instead of and.



if [ $sn -ne 3 ] && [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g')" ]; then
echo reject


Or you could just use case and a pattern match:



case "$start" in
[0-9][0-9][0-9]) echo "'$start' is ok";;
*) echo "'$start' is invalid"; exit 1;;
esac





share|improve this answer














if ( [ $# -eq 2 ] )
then
elif


As Jeff's answer says, the first if condition is missing the part with the commands. The error messages given by Bash and Dash are a bit vague, it seems like they come directly from the parser, and they haven't bothered to add a more user-friendly message there.



If you don't want to do anything inside a branch, you'll still need to add some command there. I'd suggest true, which doesn't do anything.



Fixing that, shellcheck.net gives a couple of more observations:



if ( [ $# -eq 2 ] )
^-- SC2233: Remove superfluous (..) around condition.


The parenthesis start a subshell, which is not necessary here (and involves extra overhead, like forking a subprocess in Bash).



... [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g') " ] 
>> ^--
SC2157: Argument to -n is always true due to literal strings.


You've quoted the command substitution, good! But you have an extra space there in the end. Whatever the command substitution outputs, the argument to -n will never be empty, because of that space.



(It also notes about quoting $sn and $en, which would be the careful thing to do, but isn't really necessary if you know IFS doesn't contain any digits.)





That said, I'm not sure the conditions still are quite right. You say:




I want to check the arguments provided by the user and they have to be made by only 3 digits .




But note that the test below catches only the case where sn is not three, and in addition there are other characters than numbers, i.e. it passes abc and 1234, and only rejects, say abcd. You want an or condition, ||, instead of and.



if [ $sn -ne 3 ] && [ -n "$(printf '%sn' "$start" | sed 's/[0-9]//g')" ]; then
echo reject


Or you could just use case and a pattern match:



case "$start" in
[0-9][0-9][0-9]) echo "'$start' is ok";;
*) echo "'$start' is invalid"; exit 1;;
esac






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









ilkkachu

54.1k782147




54.1k782147












  • Thank you very much , using the case statement helped !
    – bboy
    2 days ago






  • 1




    Or, with bash, if [[ $start != [0-9][0-9][0-9] ]]; then die; fi -- within double brackets, the == and != operators are pattern matching
    – glenn jackman
    2 days ago




















  • Thank you very much , using the case statement helped !
    – bboy
    2 days ago






  • 1




    Or, with bash, if [[ $start != [0-9][0-9][0-9] ]]; then die; fi -- within double brackets, the == and != operators are pattern matching
    – glenn jackman
    2 days ago


















Thank you very much , using the case statement helped !
– bboy
2 days ago




Thank you very much , using the case statement helped !
– bboy
2 days ago




1




1




Or, with bash, if [[ $start != [0-9][0-9][0-9] ]]; then die; fi -- within double brackets, the == and != operators are pattern matching
– glenn jackman
2 days ago






Or, with bash, if [[ $start != [0-9][0-9][0-9] ]]; then die; fi -- within double brackets, the == and != operators are pattern matching
– glenn jackman
2 days ago














up vote
3
down vote













You don't have any statements in the "true" case of your first if:



if ( [ $# -eq 2 ] )

then
## <-- HERE
elif ...


Quoting the bash manual:




The syntax of the if command is:



if test-commands; then
consequent-commands;
[elif more-test-commands; then
more-consequents;]
[else alternate-consequents;]
fi



Where the important bit is the consequent-commands.






share|improve this answer





















  • After updating the statement no check is done on the provided variables .
    – bboy
    2 days ago






  • 1




    @bboy: That's because you likely don't want to check if there are two arguments, you probably want to check if there is not two arguments.
    – Jesse_b
    2 days ago






  • 1




    Specifically, when using if, you have to do something if the test returns something truthy. If you only want to act when the result is falsy, you must either add a no-op to the consequent-commands, or flip the logic of the test: Either if test; then :; else thing; fi or if ! test; then thing; fi. The same holds true for elif.
    – DopeGhoti
    2 days ago















up vote
3
down vote













You don't have any statements in the "true" case of your first if:



if ( [ $# -eq 2 ] )

then
## <-- HERE
elif ...


Quoting the bash manual:




The syntax of the if command is:



if test-commands; then
consequent-commands;
[elif more-test-commands; then
more-consequents;]
[else alternate-consequents;]
fi



Where the important bit is the consequent-commands.






share|improve this answer





















  • After updating the statement no check is done on the provided variables .
    – bboy
    2 days ago






  • 1




    @bboy: That's because you likely don't want to check if there are two arguments, you probably want to check if there is not two arguments.
    – Jesse_b
    2 days ago






  • 1




    Specifically, when using if, you have to do something if the test returns something truthy. If you only want to act when the result is falsy, you must either add a no-op to the consequent-commands, or flip the logic of the test: Either if test; then :; else thing; fi or if ! test; then thing; fi. The same holds true for elif.
    – DopeGhoti
    2 days ago













up vote
3
down vote










up vote
3
down vote









You don't have any statements in the "true" case of your first if:



if ( [ $# -eq 2 ] )

then
## <-- HERE
elif ...


Quoting the bash manual:




The syntax of the if command is:



if test-commands; then
consequent-commands;
[elif more-test-commands; then
more-consequents;]
[else alternate-consequents;]
fi



Where the important bit is the consequent-commands.






share|improve this answer












You don't have any statements in the "true" case of your first if:



if ( [ $# -eq 2 ] )

then
## <-- HERE
elif ...


Quoting the bash manual:




The syntax of the if command is:



if test-commands; then
consequent-commands;
[elif more-test-commands; then
more-consequents;]
[else alternate-consequents;]
fi



Where the important bit is the consequent-commands.







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









Jeff Schaller

37k1052121




37k1052121












  • After updating the statement no check is done on the provided variables .
    – bboy
    2 days ago






  • 1




    @bboy: That's because you likely don't want to check if there are two arguments, you probably want to check if there is not two arguments.
    – Jesse_b
    2 days ago






  • 1




    Specifically, when using if, you have to do something if the test returns something truthy. If you only want to act when the result is falsy, you must either add a no-op to the consequent-commands, or flip the logic of the test: Either if test; then :; else thing; fi or if ! test; then thing; fi. The same holds true for elif.
    – DopeGhoti
    2 days ago


















  • After updating the statement no check is done on the provided variables .
    – bboy
    2 days ago






  • 1




    @bboy: That's because you likely don't want to check if there are two arguments, you probably want to check if there is not two arguments.
    – Jesse_b
    2 days ago






  • 1




    Specifically, when using if, you have to do something if the test returns something truthy. If you only want to act when the result is falsy, you must either add a no-op to the consequent-commands, or flip the logic of the test: Either if test; then :; else thing; fi or if ! test; then thing; fi. The same holds true for elif.
    – DopeGhoti
    2 days ago
















After updating the statement no check is done on the provided variables .
– bboy
2 days ago




After updating the statement no check is done on the provided variables .
– bboy
2 days ago




1




1




@bboy: That's because you likely don't want to check if there are two arguments, you probably want to check if there is not two arguments.
– Jesse_b
2 days ago




@bboy: That's because you likely don't want to check if there are two arguments, you probably want to check if there is not two arguments.
– Jesse_b
2 days ago




1




1




Specifically, when using if, you have to do something if the test returns something truthy. If you only want to act when the result is falsy, you must either add a no-op to the consequent-commands, or flip the logic of the test: Either if test; then :; else thing; fi or if ! test; then thing; fi. The same holds true for elif.
– DopeGhoti
2 days ago




Specifically, when using if, you have to do something if the test returns something truthy. If you only want to act when the result is falsy, you must either add a no-op to the consequent-commands, or flip the logic of the test: Either if test; then :; else thing; fi or if ! test; then thing; fi. The same holds true for elif.
– DopeGhoti
2 days ago










bboy is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















bboy is a new contributor. Be nice, and check out our Code of Conduct.













bboy is a new contributor. Be nice, and check out our Code of Conduct.












bboy is a new contributor. Be nice, and check out our Code of Conduct.
















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%2f484739%2felif-condition-in-an-if-statement%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

Ellipse (mathématiques)

Quarter-circle Tiles

Mont Emei