If you enable AGI debugging on the console (‘agi set debug on’) you will see the ‘conversation’ between your AGI and Asterisk.
You will profit from reading about the AGI protocol. Your snippet violates the protocol in a couple of ways. It may work for something as simple as a single ‘set variable’ but not following the protocol may fail in unexpected and difficult to debug ways.
Bash (IMO) is not a great language for writing AGIs. I would suggest one of the ‘P’ languages with a AGI library. I’m sure others may have had success in minor projects, but do you really want to ‘swim upstream?’
Properly using an existing library is the path to success in AGIs.
Your specific error is caused by not quoting $TEXT correctly in your echo statement.
Rarely I use AGI and when I needed it was for simple answers.
I tried to script in php, got the same error:
I do not like the idea of have to recur to a library to this simple request where the answer come in a sentence insted a word, I would like to have control of the script and not depend of external fonts.
I thought about that, but didn’t find a way to make it work, for exemple:
If your PHP script sent the exact same request, I would expect the exact same response
I was proposing that a ‘P’ language + an established library is the road to success for most. (Personally, I use C with a library that I coded almost 20 years ago for most AGIs)
Doing it the ‘right way’ may seem more effort that it is worth, but the experience will open more doors for you. You may decide that writing most of your application as an AGI (or a series of AGIs) and just using dialplan for the ‘glue’ to hold it all together makes more sense.
Writing an application as an AGI has many advantages.
If you were to observe the same request issued by a ‘battle tested’ library you would see that Asterisk wants double quotes surrounding the value instead of single quotes. Personally, I would have coded it to accept both
Just for clarification, this topic should be named “How to use SET VARIABLE when the value has spaces” because you can have spaces in the variable’s name if you double quote it – but I’d advise against it