Shell_command argument with space

Good morning,
already I apologize in advance for my English.
I can’t pass a message that contains spaces,only the first word.
If I add a | urlencode I have the full message with the %20 as a space. I think I have gone around the topics and all the forms of

" ' { ...

I leave you the example:
notification_sms: bash scripts/ sms "{{ notification }}"
notification_sms: 'echo var1: 1 , var2: "{{ notification }}", var3: 3 >> scripts/testsms.txt '
notification_sms: 'echo {{ notification }} >> scripts/testsms.txt '

service: shell_command.notification_sms
   notification: '{{ "sms test" }}'

Thanks in advance.

Uhm, I can’t understand completely what you do but this is an example I made that works (edited for security):

   set_ipmi_fan: /config/custom_commands/ xx.xx.xx.xx {{states("input_number.rear_fan_1")|int}} {{states("input_number.rear_fan_2")|int}} {{states("input_number.front_fan_1")|int}} {{states("input_number.front_fan_2")|int}} {{states("input_number.front_fan_3")|int}}

There’s no need to put “bash” before calling a bash script ( is a bash script) and no need for quotes/backticks either.

Wait, now I get what you mean, the variable {{ notification }} contains spaces and it gets cut, right?
Is there a way you could cut the command in two, so that the text is already in a file when you call the script and the script gets the message from the text file?

Can you show us the bash scripts? I suspect you collect the “notification” argument with $2, if the argument is not passed as a whole string it will only take the first word.

For example, if this is my script:

echo $1 $2

When I call it like this:

./ sms my text goes here

it will echo:

sms my

In order to have the whole text I have to quote it:

./ sms "my text goes here"

Which will result in:

sms my text goes here

You might have to “escape” the quotes in your shell command, like this:

notification_sms: bash scripts/ sms \"{{ notification }}\"

So that they get passed on to the command.

Thanks for your answers.
But if i put this :

service: shell_command.notification_sms
  notification: my text goes here or "my text goes here"

notification_sms: bash scripts/ sms \"{{ notification }}\"

I obtain this :

Yeah, I am not sure exactly how to pull it off, but I am almost certain the issue is for the bash script, not the HA part.
Actually, the fact that your message shows the quotes ("my) kinda says that the quotes are passed on to the script but not interpreted as such.
There might be a better way to escape the double quotes. I’ll see if I can do some research.

I created the following command:

   notification: /config/custom_commands/ sms "message test" > /config/custom_commands/sms_notify

The command was called manually and worked just fine. The file contained the full text (“sms message test”) despite printing only $1 and $2.

So I modified the command as such:

notification: /config/custom_commands/ sms "{{states('input_text.notification')}}"

in order for it to take the value of a variable (in this case a helper text box).
This time it worked.

Ok but if you want to send it with automation script like (not with an input text)

Shell Command:

service: shell_command.notification_sms
  notification: "{{ \"my text goes here\" }}" 
notification: "{{ my text goes here }}" 

I’d say the first one, but you might try putting in an input_text first to see if it works.

I find the good way:

notification_sms: "bash scripts/ sms \"{{notification}}\""

service: shell_command.notification_sms
  notification: my text goes here

Thanks @ll

1 Like