简体   繁体   中英

How do I send a message with textbelt with user input using bash?

I am trying to set up a relatively simple system where I can send sms messages using textbelt in bash. The idea is there is a very simple prompt where it asks what number you would like to message and what you would like to say. The issue I am running into is that when I try to use the read varnumber command to save the number inputted to a variable, textbelt only sends the first word in the message. Because there is a space in the message, the code ignores the rest of the message. It is a bit hard to explain but I posted the code here Please give it a look and let me know what I am doing wrong.

General rule:

Quote it if it can either be empty or contain spaces (or any whitespace really) or special characters (wildcards). Not quoting strings with spaces often leads to the shell breaking apart a single argument into many.

So putting the variables in your curl query in quotes, should solve the problem.

curl -X POST https://textbelt.com/text \
    --data-urlencode phone="$varnumber" \
    --data-urlencode message="$varmessage" \
    -d key=textbelt

Also, you may want to put your console output into quotes:

echo "Whatever you want to write here"

Or to combine output/input you could use read -p :

read -p "What is your phonenumber? " varnumber

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM