How to surpress error message from if statement in unix [closed]

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











up vote
-1
down vote

favorite












How do I want to suppress error message from the if statement. I need to use exit 1 command because I want to terminate the shell script if the if statement is true. I can't use exit 0 as if will jump to the next command. But if I use exit 1, it will display an error. The command and the output is like below.



command:



if [ ! $(name) ] 2> /dev/null; then 
echo " No Name"; exit 1;fi


output:



No Name
make: *** [info] Error 1


The output is correct but the makefile display this error make: * [info] Error 1**



Here is my reference website, but it still can't work.



1) https://askubuntu.com/questions/474556/hiding-output-of-a-command



2) https://stackoverflow.com/questions/15678796/suppress-shell-script-error-messages










share|improve this question













closed as unclear what you're asking by Kusalananda, mosvy, Thomas, X Tian, JigglyNaga Nov 30 at 12:01


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 4




    The error message isn't coming from the if command, but from make. This is how make tells you the build process has aborted. Is "name" really a call to make? Or is this if command being called from within a Makefile? You may want to update the question with more information around how this is being called, and what you expect to happen.
    – Stephen Harris
    Nov 30 at 2:53











  • How can I fix this error
    – daffodil
    Nov 30 at 2:54










  • @StephenHarris Yes it is a call, some of the file has $(name) and some of the file doesn't have $(name). I want the file that doesn't has $(name) to echo, "No name"
    – daffodil
    Nov 30 at 5:29











  • On a tangent: $(name) will undergo word splitting, so might be split into multiple parts and cause an error in the [ syntax. Put it in double quotes " to avoid that.
    – n.st
    Nov 30 at 5:36






  • 2




    "How can I fix this error?" Well, you are explicitly exiting with a non-zero exit status, which means that the make target failed to build. Make will treat this as a failure to build the target and notify the user about it by printing the error string. You generated the error, why would you want to "fix" it, and what do you mean by that? Are you asking why the name variable is empty?
    – Kusalananda
    Nov 30 at 9:04














up vote
-1
down vote

favorite












How do I want to suppress error message from the if statement. I need to use exit 1 command because I want to terminate the shell script if the if statement is true. I can't use exit 0 as if will jump to the next command. But if I use exit 1, it will display an error. The command and the output is like below.



command:



if [ ! $(name) ] 2> /dev/null; then 
echo " No Name"; exit 1;fi


output:



No Name
make: *** [info] Error 1


The output is correct but the makefile display this error make: * [info] Error 1**



Here is my reference website, but it still can't work.



1) https://askubuntu.com/questions/474556/hiding-output-of-a-command



2) https://stackoverflow.com/questions/15678796/suppress-shell-script-error-messages










share|improve this question













closed as unclear what you're asking by Kusalananda, mosvy, Thomas, X Tian, JigglyNaga Nov 30 at 12:01


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 4




    The error message isn't coming from the if command, but from make. This is how make tells you the build process has aborted. Is "name" really a call to make? Or is this if command being called from within a Makefile? You may want to update the question with more information around how this is being called, and what you expect to happen.
    – Stephen Harris
    Nov 30 at 2:53











  • How can I fix this error
    – daffodil
    Nov 30 at 2:54










  • @StephenHarris Yes it is a call, some of the file has $(name) and some of the file doesn't have $(name). I want the file that doesn't has $(name) to echo, "No name"
    – daffodil
    Nov 30 at 5:29











  • On a tangent: $(name) will undergo word splitting, so might be split into multiple parts and cause an error in the [ syntax. Put it in double quotes " to avoid that.
    – n.st
    Nov 30 at 5:36






  • 2




    "How can I fix this error?" Well, you are explicitly exiting with a non-zero exit status, which means that the make target failed to build. Make will treat this as a failure to build the target and notify the user about it by printing the error string. You generated the error, why would you want to "fix" it, and what do you mean by that? Are you asking why the name variable is empty?
    – Kusalananda
    Nov 30 at 9:04












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











How do I want to suppress error message from the if statement. I need to use exit 1 command because I want to terminate the shell script if the if statement is true. I can't use exit 0 as if will jump to the next command. But if I use exit 1, it will display an error. The command and the output is like below.



command:



if [ ! $(name) ] 2> /dev/null; then 
echo " No Name"; exit 1;fi


output:



No Name
make: *** [info] Error 1


The output is correct but the makefile display this error make: * [info] Error 1**



Here is my reference website, but it still can't work.



1) https://askubuntu.com/questions/474556/hiding-output-of-a-command



2) https://stackoverflow.com/questions/15678796/suppress-shell-script-error-messages










share|improve this question













How do I want to suppress error message from the if statement. I need to use exit 1 command because I want to terminate the shell script if the if statement is true. I can't use exit 0 as if will jump to the next command. But if I use exit 1, it will display an error. The command and the output is like below.



command:



if [ ! $(name) ] 2> /dev/null; then 
echo " No Name"; exit 1;fi


output:



No Name
make: *** [info] Error 1


The output is correct but the makefile display this error make: * [info] Error 1**



Here is my reference website, but it still can't work.



1) https://askubuntu.com/questions/474556/hiding-output-of-a-command



2) https://stackoverflow.com/questions/15678796/suppress-shell-script-error-messages







shell make error-handling






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 30 at 2:22









daffodil

375




375




closed as unclear what you're asking by Kusalananda, mosvy, Thomas, X Tian, JigglyNaga Nov 30 at 12:01


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by Kusalananda, mosvy, Thomas, X Tian, JigglyNaga Nov 30 at 12:01


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 4




    The error message isn't coming from the if command, but from make. This is how make tells you the build process has aborted. Is "name" really a call to make? Or is this if command being called from within a Makefile? You may want to update the question with more information around how this is being called, and what you expect to happen.
    – Stephen Harris
    Nov 30 at 2:53











  • How can I fix this error
    – daffodil
    Nov 30 at 2:54










  • @StephenHarris Yes it is a call, some of the file has $(name) and some of the file doesn't have $(name). I want the file that doesn't has $(name) to echo, "No name"
    – daffodil
    Nov 30 at 5:29











  • On a tangent: $(name) will undergo word splitting, so might be split into multiple parts and cause an error in the [ syntax. Put it in double quotes " to avoid that.
    – n.st
    Nov 30 at 5:36






  • 2




    "How can I fix this error?" Well, you are explicitly exiting with a non-zero exit status, which means that the make target failed to build. Make will treat this as a failure to build the target and notify the user about it by printing the error string. You generated the error, why would you want to "fix" it, and what do you mean by that? Are you asking why the name variable is empty?
    – Kusalananda
    Nov 30 at 9:04












  • 4




    The error message isn't coming from the if command, but from make. This is how make tells you the build process has aborted. Is "name" really a call to make? Or is this if command being called from within a Makefile? You may want to update the question with more information around how this is being called, and what you expect to happen.
    – Stephen Harris
    Nov 30 at 2:53











  • How can I fix this error
    – daffodil
    Nov 30 at 2:54










  • @StephenHarris Yes it is a call, some of the file has $(name) and some of the file doesn't have $(name). I want the file that doesn't has $(name) to echo, "No name"
    – daffodil
    Nov 30 at 5:29











  • On a tangent: $(name) will undergo word splitting, so might be split into multiple parts and cause an error in the [ syntax. Put it in double quotes " to avoid that.
    – n.st
    Nov 30 at 5:36






  • 2




    "How can I fix this error?" Well, you are explicitly exiting with a non-zero exit status, which means that the make target failed to build. Make will treat this as a failure to build the target and notify the user about it by printing the error string. You generated the error, why would you want to "fix" it, and what do you mean by that? Are you asking why the name variable is empty?
    – Kusalananda
    Nov 30 at 9:04







4




4




The error message isn't coming from the if command, but from make. This is how make tells you the build process has aborted. Is "name" really a call to make? Or is this if command being called from within a Makefile? You may want to update the question with more information around how this is being called, and what you expect to happen.
– Stephen Harris
Nov 30 at 2:53





The error message isn't coming from the if command, but from make. This is how make tells you the build process has aborted. Is "name" really a call to make? Or is this if command being called from within a Makefile? You may want to update the question with more information around how this is being called, and what you expect to happen.
– Stephen Harris
Nov 30 at 2:53













How can I fix this error
– daffodil
Nov 30 at 2:54




How can I fix this error
– daffodil
Nov 30 at 2:54












@StephenHarris Yes it is a call, some of the file has $(name) and some of the file doesn't have $(name). I want the file that doesn't has $(name) to echo, "No name"
– daffodil
Nov 30 at 5:29





@StephenHarris Yes it is a call, some of the file has $(name) and some of the file doesn't have $(name). I want the file that doesn't has $(name) to echo, "No name"
– daffodil
Nov 30 at 5:29













On a tangent: $(name) will undergo word splitting, so might be split into multiple parts and cause an error in the [ syntax. Put it in double quotes " to avoid that.
– n.st
Nov 30 at 5:36




On a tangent: $(name) will undergo word splitting, so might be split into multiple parts and cause an error in the [ syntax. Put it in double quotes " to avoid that.
– n.st
Nov 30 at 5:36




2




2




"How can I fix this error?" Well, you are explicitly exiting with a non-zero exit status, which means that the make target failed to build. Make will treat this as a failure to build the target and notify the user about it by printing the error string. You generated the error, why would you want to "fix" it, and what do you mean by that? Are you asking why the name variable is empty?
– Kusalananda
Nov 30 at 9:04




"How can I fix this error?" Well, you are explicitly exiting with a non-zero exit status, which means that the make target failed to build. Make will treat this as a failure to build the target and notify the user about it by printing the error string. You generated the error, why would you want to "fix" it, and what do you mean by that? Are you asking why the name variable is empty?
– Kusalananda
Nov 30 at 9:04















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

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