Bash usage in Windows: “Cannot send an empty message” error












2















So I need a way to send some webhooks to discord from a Windows machine, doing so in Linux is a no problems with curl, so I installed Ubuntu 18 LTS onto the machine from the Windows Apps store and gave it a go.



Here is where the problems start, when I use the same command in Windows:



bash -c "curl -H "Content-Type:application/json" -X POST -d '{"x": "x", "content": "hello"}' https://discordapp.com/api/webhooks/536660752111763477/zkW73A97-TNJVcH3xMCK0GMHEkwqKNWSfslA0WxxxxxxMYOLTRi6UMXYR_QLDCfxIJ_d"


I get this error:



{"code": 50006, "message": "Cannot send an empty message"}


What is it in that string that Windows doesn't like?



I messed with spaces and other stuff but only broke more.










share|improve this question









New contributor




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





















  • You shared your discord webhook url, did you change some characters inside it to make it invalid? If not, regenerate it before people start hacking you

    – Ferrybig
    40 mins ago
















2















So I need a way to send some webhooks to discord from a Windows machine, doing so in Linux is a no problems with curl, so I installed Ubuntu 18 LTS onto the machine from the Windows Apps store and gave it a go.



Here is where the problems start, when I use the same command in Windows:



bash -c "curl -H "Content-Type:application/json" -X POST -d '{"x": "x", "content": "hello"}' https://discordapp.com/api/webhooks/536660752111763477/zkW73A97-TNJVcH3xMCK0GMHEkwqKNWSfslA0WxxxxxxMYOLTRi6UMXYR_QLDCfxIJ_d"


I get this error:



{"code": 50006, "message": "Cannot send an empty message"}


What is it in that string that Windows doesn't like?



I messed with spaces and other stuff but only broke more.










share|improve this question









New contributor




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





















  • You shared your discord webhook url, did you change some characters inside it to make it invalid? If not, regenerate it before people start hacking you

    – Ferrybig
    40 mins ago














2












2








2








So I need a way to send some webhooks to discord from a Windows machine, doing so in Linux is a no problems with curl, so I installed Ubuntu 18 LTS onto the machine from the Windows Apps store and gave it a go.



Here is where the problems start, when I use the same command in Windows:



bash -c "curl -H "Content-Type:application/json" -X POST -d '{"x": "x", "content": "hello"}' https://discordapp.com/api/webhooks/536660752111763477/zkW73A97-TNJVcH3xMCK0GMHEkwqKNWSfslA0WxxxxxxMYOLTRi6UMXYR_QLDCfxIJ_d"


I get this error:



{"code": 50006, "message": "Cannot send an empty message"}


What is it in that string that Windows doesn't like?



I messed with spaces and other stuff but only broke more.










share|improve this question









New contributor




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












So I need a way to send some webhooks to discord from a Windows machine, doing so in Linux is a no problems with curl, so I installed Ubuntu 18 LTS onto the machine from the Windows Apps store and gave it a go.



Here is where the problems start, when I use the same command in Windows:



bash -c "curl -H "Content-Type:application/json" -X POST -d '{"x": "x", "content": "hello"}' https://discordapp.com/api/webhooks/536660752111763477/zkW73A97-TNJVcH3xMCK0GMHEkwqKNWSfslA0WxxxxxxMYOLTRi6UMXYR_QLDCfxIJ_d"


I get this error:



{"code": 50006, "message": "Cannot send an empty message"}


What is it in that string that Windows doesn't like?



I messed with spaces and other stuff but only broke more.







18.04 bash windows windows-subsystem-for-linux






share|improve this question









New contributor




Kieeps 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




Kieeps 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 1 hour ago









pomsky

29.7k1190117




29.7k1190117






New contributor




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









asked 4 hours ago









KieepsKieeps

133




133




New contributor




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





New contributor





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






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













  • You shared your discord webhook url, did you change some characters inside it to make it invalid? If not, regenerate it before people start hacking you

    – Ferrybig
    40 mins ago



















  • You shared your discord webhook url, did you change some characters inside it to make it invalid? If not, regenerate it before people start hacking you

    – Ferrybig
    40 mins ago

















You shared your discord webhook url, did you change some characters inside it to make it invalid? If not, regenerate it before people start hacking you

– Ferrybig
40 mins ago





You shared your discord webhook url, did you change some characters inside it to make it invalid? If not, regenerate it before people start hacking you

– Ferrybig
40 mins ago










1 Answer
1






active

oldest

votes


















3














The problem in your script is actually shown very clearly by the Ask Ubuntu syntax highlighting - as you can see in your answer, the "x" in your post is colored black, because it is outside of the double-quoted string that is the value for the -c parameter to bash. This problem is repeated throughout your code.



The way strings work in shell is that the double-quotes are a way to get multiple words (i.e. character sequences containing spaces) to appear as a single word for the shell. The shell then passes these words as is - without the enclosing string double-quotes - to the program for running. You can also cause text to be bunched into the same word by just squizzing the text together without spaces.



So the following commands are all the same for the shell, and will show the same output:




  • echo 123

  • echo "1"23

  • echo "1"2"3"

  • echo "1"'2'"3"


In all cases echo just sees the text "123" (the last one I put in some single quotes, which for a lot of effects behaves the same.



So with that in mind, let's analyze your script line:



bash -c "curl -H "Content-Type:application/json" -X POST -d '{"x": "x", "content": "hello"}' https://discordapp.com/some/path"


We can see that you are passing a lot of code to bash as the -c parameter, which is "the command to run". So bash will be run with two arguments - the first one is -c and the second one is all the text that should be considered "the command". The second argument uses double-quoted strings (yes, plural) to encode some spaces and other shell characters so they will be passed as is to the "command to run" parameter.



Let us do manually what the shell does to understand the second parameter, by converting all "words" as a classic programming language string array:



var a = [
"-c",
"curl -H " + "Content-Type:application/json" + " -X POST -d '{" + "x" +
": " + "x" + ", " + "content" + ": " + "hello" +
"}' https://discordapp.com/some/path"
]


Then the shell will resolve the list of strings and will execute bash:



execve("bash", "-c", "curl -H Content-Type:application/json -X POST -d '{x: x, content: hello}' https://discordapp.com/some/path");


As you can see there are no more double quotes inside the JSON POST payload: they were removed by the shell trying to understand what strings make up the second argument. This causes the payload to become invalid and the server to think you didn't provide an input.



BTW: from my experience - what you've just demonstrated is the number 1 misunderstanding of how shell escaping work, so don't feel bad about it - everybody's doing it ;-)



What you want to do, if you want to put double quotes inside a double-quoted string is to "escape" them - make the shell not see them as special characters but as just part of the text of the string. There are two major ways to do this:




  1. take advantage of the fact that strings in shell do not actually require quoting and could just be words bunched together without spaces, or multiple quoted string bunched together without spaces. So it could look like this: "curl -H "'"'"Content-Type:application/json"'"'" ...". You can see that instead of just putting a double-quote, we understand that double-quote actually terminates the string started at the beginning and isn't actually part of the input, and before the shell sees the end of the input (due to a space) we immediately start a new string, this one delimited by single quotes - that contain only a double-quote character, and so on - this is actually similar to the last echo command in the first example.

  2. use backslash to cause the internal double-quote characters to not be considered string delimiters - escape them from parsing: "curl -H "Content-Type:application/json" -X...


I personally prefer the first method.






share|improve this answer



















  • 1





    "teach a man to fish" comes to mind :-) thanks for the extreamly good explanation, it didn't just help me fix the string above, it helped me modify it with variables :-D I'm very grateful :-)

    – Kieeps
    3 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});


}
});






Kieeps 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%2faskubuntu.com%2fquestions%2f1111565%2fbash-usage-in-windows-cannot-send-an-empty-message-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














The problem in your script is actually shown very clearly by the Ask Ubuntu syntax highlighting - as you can see in your answer, the "x" in your post is colored black, because it is outside of the double-quoted string that is the value for the -c parameter to bash. This problem is repeated throughout your code.



The way strings work in shell is that the double-quotes are a way to get multiple words (i.e. character sequences containing spaces) to appear as a single word for the shell. The shell then passes these words as is - without the enclosing string double-quotes - to the program for running. You can also cause text to be bunched into the same word by just squizzing the text together without spaces.



So the following commands are all the same for the shell, and will show the same output:




  • echo 123

  • echo "1"23

  • echo "1"2"3"

  • echo "1"'2'"3"


In all cases echo just sees the text "123" (the last one I put in some single quotes, which for a lot of effects behaves the same.



So with that in mind, let's analyze your script line:



bash -c "curl -H "Content-Type:application/json" -X POST -d '{"x": "x", "content": "hello"}' https://discordapp.com/some/path"


We can see that you are passing a lot of code to bash as the -c parameter, which is "the command to run". So bash will be run with two arguments - the first one is -c and the second one is all the text that should be considered "the command". The second argument uses double-quoted strings (yes, plural) to encode some spaces and other shell characters so they will be passed as is to the "command to run" parameter.



Let us do manually what the shell does to understand the second parameter, by converting all "words" as a classic programming language string array:



var a = [
"-c",
"curl -H " + "Content-Type:application/json" + " -X POST -d '{" + "x" +
": " + "x" + ", " + "content" + ": " + "hello" +
"}' https://discordapp.com/some/path"
]


Then the shell will resolve the list of strings and will execute bash:



execve("bash", "-c", "curl -H Content-Type:application/json -X POST -d '{x: x, content: hello}' https://discordapp.com/some/path");


As you can see there are no more double quotes inside the JSON POST payload: they were removed by the shell trying to understand what strings make up the second argument. This causes the payload to become invalid and the server to think you didn't provide an input.



BTW: from my experience - what you've just demonstrated is the number 1 misunderstanding of how shell escaping work, so don't feel bad about it - everybody's doing it ;-)



What you want to do, if you want to put double quotes inside a double-quoted string is to "escape" them - make the shell not see them as special characters but as just part of the text of the string. There are two major ways to do this:




  1. take advantage of the fact that strings in shell do not actually require quoting and could just be words bunched together without spaces, or multiple quoted string bunched together without spaces. So it could look like this: "curl -H "'"'"Content-Type:application/json"'"'" ...". You can see that instead of just putting a double-quote, we understand that double-quote actually terminates the string started at the beginning and isn't actually part of the input, and before the shell sees the end of the input (due to a space) we immediately start a new string, this one delimited by single quotes - that contain only a double-quote character, and so on - this is actually similar to the last echo command in the first example.

  2. use backslash to cause the internal double-quote characters to not be considered string delimiters - escape them from parsing: "curl -H "Content-Type:application/json" -X...


I personally prefer the first method.






share|improve this answer



















  • 1





    "teach a man to fish" comes to mind :-) thanks for the extreamly good explanation, it didn't just help me fix the string above, it helped me modify it with variables :-D I'm very grateful :-)

    – Kieeps
    3 hours ago
















3














The problem in your script is actually shown very clearly by the Ask Ubuntu syntax highlighting - as you can see in your answer, the "x" in your post is colored black, because it is outside of the double-quoted string that is the value for the -c parameter to bash. This problem is repeated throughout your code.



The way strings work in shell is that the double-quotes are a way to get multiple words (i.e. character sequences containing spaces) to appear as a single word for the shell. The shell then passes these words as is - without the enclosing string double-quotes - to the program for running. You can also cause text to be bunched into the same word by just squizzing the text together without spaces.



So the following commands are all the same for the shell, and will show the same output:




  • echo 123

  • echo "1"23

  • echo "1"2"3"

  • echo "1"'2'"3"


In all cases echo just sees the text "123" (the last one I put in some single quotes, which for a lot of effects behaves the same.



So with that in mind, let's analyze your script line:



bash -c "curl -H "Content-Type:application/json" -X POST -d '{"x": "x", "content": "hello"}' https://discordapp.com/some/path"


We can see that you are passing a lot of code to bash as the -c parameter, which is "the command to run". So bash will be run with two arguments - the first one is -c and the second one is all the text that should be considered "the command". The second argument uses double-quoted strings (yes, plural) to encode some spaces and other shell characters so they will be passed as is to the "command to run" parameter.



Let us do manually what the shell does to understand the second parameter, by converting all "words" as a classic programming language string array:



var a = [
"-c",
"curl -H " + "Content-Type:application/json" + " -X POST -d '{" + "x" +
": " + "x" + ", " + "content" + ": " + "hello" +
"}' https://discordapp.com/some/path"
]


Then the shell will resolve the list of strings and will execute bash:



execve("bash", "-c", "curl -H Content-Type:application/json -X POST -d '{x: x, content: hello}' https://discordapp.com/some/path");


As you can see there are no more double quotes inside the JSON POST payload: they were removed by the shell trying to understand what strings make up the second argument. This causes the payload to become invalid and the server to think you didn't provide an input.



BTW: from my experience - what you've just demonstrated is the number 1 misunderstanding of how shell escaping work, so don't feel bad about it - everybody's doing it ;-)



What you want to do, if you want to put double quotes inside a double-quoted string is to "escape" them - make the shell not see them as special characters but as just part of the text of the string. There are two major ways to do this:




  1. take advantage of the fact that strings in shell do not actually require quoting and could just be words bunched together without spaces, or multiple quoted string bunched together without spaces. So it could look like this: "curl -H "'"'"Content-Type:application/json"'"'" ...". You can see that instead of just putting a double-quote, we understand that double-quote actually terminates the string started at the beginning and isn't actually part of the input, and before the shell sees the end of the input (due to a space) we immediately start a new string, this one delimited by single quotes - that contain only a double-quote character, and so on - this is actually similar to the last echo command in the first example.

  2. use backslash to cause the internal double-quote characters to not be considered string delimiters - escape them from parsing: "curl -H "Content-Type:application/json" -X...


I personally prefer the first method.






share|improve this answer



















  • 1





    "teach a man to fish" comes to mind :-) thanks for the extreamly good explanation, it didn't just help me fix the string above, it helped me modify it with variables :-D I'm very grateful :-)

    – Kieeps
    3 hours ago














3












3








3







The problem in your script is actually shown very clearly by the Ask Ubuntu syntax highlighting - as you can see in your answer, the "x" in your post is colored black, because it is outside of the double-quoted string that is the value for the -c parameter to bash. This problem is repeated throughout your code.



The way strings work in shell is that the double-quotes are a way to get multiple words (i.e. character sequences containing spaces) to appear as a single word for the shell. The shell then passes these words as is - without the enclosing string double-quotes - to the program for running. You can also cause text to be bunched into the same word by just squizzing the text together without spaces.



So the following commands are all the same for the shell, and will show the same output:




  • echo 123

  • echo "1"23

  • echo "1"2"3"

  • echo "1"'2'"3"


In all cases echo just sees the text "123" (the last one I put in some single quotes, which for a lot of effects behaves the same.



So with that in mind, let's analyze your script line:



bash -c "curl -H "Content-Type:application/json" -X POST -d '{"x": "x", "content": "hello"}' https://discordapp.com/some/path"


We can see that you are passing a lot of code to bash as the -c parameter, which is "the command to run". So bash will be run with two arguments - the first one is -c and the second one is all the text that should be considered "the command". The second argument uses double-quoted strings (yes, plural) to encode some spaces and other shell characters so they will be passed as is to the "command to run" parameter.



Let us do manually what the shell does to understand the second parameter, by converting all "words" as a classic programming language string array:



var a = [
"-c",
"curl -H " + "Content-Type:application/json" + " -X POST -d '{" + "x" +
": " + "x" + ", " + "content" + ": " + "hello" +
"}' https://discordapp.com/some/path"
]


Then the shell will resolve the list of strings and will execute bash:



execve("bash", "-c", "curl -H Content-Type:application/json -X POST -d '{x: x, content: hello}' https://discordapp.com/some/path");


As you can see there are no more double quotes inside the JSON POST payload: they were removed by the shell trying to understand what strings make up the second argument. This causes the payload to become invalid and the server to think you didn't provide an input.



BTW: from my experience - what you've just demonstrated is the number 1 misunderstanding of how shell escaping work, so don't feel bad about it - everybody's doing it ;-)



What you want to do, if you want to put double quotes inside a double-quoted string is to "escape" them - make the shell not see them as special characters but as just part of the text of the string. There are two major ways to do this:




  1. take advantage of the fact that strings in shell do not actually require quoting and could just be words bunched together without spaces, or multiple quoted string bunched together without spaces. So it could look like this: "curl -H "'"'"Content-Type:application/json"'"'" ...". You can see that instead of just putting a double-quote, we understand that double-quote actually terminates the string started at the beginning and isn't actually part of the input, and before the shell sees the end of the input (due to a space) we immediately start a new string, this one delimited by single quotes - that contain only a double-quote character, and so on - this is actually similar to the last echo command in the first example.

  2. use backslash to cause the internal double-quote characters to not be considered string delimiters - escape them from parsing: "curl -H "Content-Type:application/json" -X...


I personally prefer the first method.






share|improve this answer













The problem in your script is actually shown very clearly by the Ask Ubuntu syntax highlighting - as you can see in your answer, the "x" in your post is colored black, because it is outside of the double-quoted string that is the value for the -c parameter to bash. This problem is repeated throughout your code.



The way strings work in shell is that the double-quotes are a way to get multiple words (i.e. character sequences containing spaces) to appear as a single word for the shell. The shell then passes these words as is - without the enclosing string double-quotes - to the program for running. You can also cause text to be bunched into the same word by just squizzing the text together without spaces.



So the following commands are all the same for the shell, and will show the same output:




  • echo 123

  • echo "1"23

  • echo "1"2"3"

  • echo "1"'2'"3"


In all cases echo just sees the text "123" (the last one I put in some single quotes, which for a lot of effects behaves the same.



So with that in mind, let's analyze your script line:



bash -c "curl -H "Content-Type:application/json" -X POST -d '{"x": "x", "content": "hello"}' https://discordapp.com/some/path"


We can see that you are passing a lot of code to bash as the -c parameter, which is "the command to run". So bash will be run with two arguments - the first one is -c and the second one is all the text that should be considered "the command". The second argument uses double-quoted strings (yes, plural) to encode some spaces and other shell characters so they will be passed as is to the "command to run" parameter.



Let us do manually what the shell does to understand the second parameter, by converting all "words" as a classic programming language string array:



var a = [
"-c",
"curl -H " + "Content-Type:application/json" + " -X POST -d '{" + "x" +
": " + "x" + ", " + "content" + ": " + "hello" +
"}' https://discordapp.com/some/path"
]


Then the shell will resolve the list of strings and will execute bash:



execve("bash", "-c", "curl -H Content-Type:application/json -X POST -d '{x: x, content: hello}' https://discordapp.com/some/path");


As you can see there are no more double quotes inside the JSON POST payload: they were removed by the shell trying to understand what strings make up the second argument. This causes the payload to become invalid and the server to think you didn't provide an input.



BTW: from my experience - what you've just demonstrated is the number 1 misunderstanding of how shell escaping work, so don't feel bad about it - everybody's doing it ;-)



What you want to do, if you want to put double quotes inside a double-quoted string is to "escape" them - make the shell not see them as special characters but as just part of the text of the string. There are two major ways to do this:




  1. take advantage of the fact that strings in shell do not actually require quoting and could just be words bunched together without spaces, or multiple quoted string bunched together without spaces. So it could look like this: "curl -H "'"'"Content-Type:application/json"'"'" ...". You can see that instead of just putting a double-quote, we understand that double-quote actually terminates the string started at the beginning and isn't actually part of the input, and before the shell sees the end of the input (due to a space) we immediately start a new string, this one delimited by single quotes - that contain only a double-quote character, and so on - this is actually similar to the last echo command in the first example.

  2. use backslash to cause the internal double-quote characters to not be considered string delimiters - escape them from parsing: "curl -H "Content-Type:application/json" -X...


I personally prefer the first method.







share|improve this answer












share|improve this answer



share|improve this answer










answered 3 hours ago









GussGuss

2,20312135




2,20312135








  • 1





    "teach a man to fish" comes to mind :-) thanks for the extreamly good explanation, it didn't just help me fix the string above, it helped me modify it with variables :-D I'm very grateful :-)

    – Kieeps
    3 hours ago














  • 1





    "teach a man to fish" comes to mind :-) thanks for the extreamly good explanation, it didn't just help me fix the string above, it helped me modify it with variables :-D I'm very grateful :-)

    – Kieeps
    3 hours ago








1




1





"teach a man to fish" comes to mind :-) thanks for the extreamly good explanation, it didn't just help me fix the string above, it helped me modify it with variables :-D I'm very grateful :-)

– Kieeps
3 hours ago





"teach a man to fish" comes to mind :-) thanks for the extreamly good explanation, it didn't just help me fix the string above, it helped me modify it with variables :-D I'm very grateful :-)

– Kieeps
3 hours ago










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










draft saved

draft discarded


















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













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












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
















Thanks for contributing an answer to Ask Ubuntu!


  • 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%2faskubuntu.com%2fquestions%2f1111565%2fbash-usage-in-windows-cannot-send-an-empty-message-error%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

Ponta tanko

Tantalo (mitologio)

Erzsébet Schaár