[LINUX] Description method for reusing variables in shellscript


I use Rocket.Chat internally, but I want to be notified of the result of cron processing on the ubuntu server as a chatbot.
The curl command is issued from Rocket.Chat by the mechanism of Webhook, but I stumbled upon the method of sending the variable created in the shell executed by cron to the chat with the curl command, so I will leave the solution


Receive variables with the curl command so that you can get different results depending on the situation

curl shape

First, check Rocket.Chat for the basic curl command issued by Webhook

curl -X POST -H 'Content-Type: application/json' --data '{"text":"Example message","attachments":[{"title":"Rocket.Chat","title_link":"https://rocket.chat","text":"Rocket.Chat, the best open source chat","image_url":"https://rocket.chat/images/mockup.png ","color":"#764FA5"}]}' https://〜〜

Skip only text

If you want to skip only plain text, write as follows

curl -X POST -H 'Content-Type: application/json' --data '{"text":"hogehoge"}' https://〜〜

Use variables

When using variables, do the following

The conclusion is
Surrounded by

curl -X POST -H 'Content-Type: application/json' --data '{"text":"'"$fuga"'"}' https://〜〜

Text + Variables

If you want to use fixed statements and variables

curl -X POST -H 'Content-Type: application/json' --data '{"text":"hogehoge'"$fuga"'"}' https://〜〜

Like this

At the end

It looks awkward, but now you can use it.
Please refer to it if you use it someday.

At first I thought this was only possible when using variables with curl, but
Actually, it seems that it was a method used when you want to reuse variables when writing shell scripts etc.

Recommended Posts

Description method for reusing variables in shellscript
[Python] No value for argument'self' in unbound method call
List method for nested resources in Django REST framework
Python code for k-means method in super simple case
Simplex method (simplex method) in Python
Private method in python
Gurobi-like optimization description method
List method argument information for classes and modules in Python
How to define multiple variables in a python for statement
Search for variables in pandas.DataFrame and get the corresponding row.
Newton's method in C ++, Python, Go (for understanding function objects)