# Sending Linux Variables to Discord Webhook from Linux Bash Shell Script

**URL:** <https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18>\
**Category:** Website Posts\
**Tags:** tutorials, technology\
**Created:** [February 24, 2020, 10:50am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18 "2020-02-24T10:50:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forums.jasonloong.com/uploads/default/original/1X/b706f160fcd96817df9f310f5cf26bbbd7d9fbd7.png) [@system](https://forums.jasonloong.com/u/system)\
**Post date:** [February 24, 2020, 10:50am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/1 "2020-02-24T10:50:00Z")

</div>

Originally published at: [Sending Linux Variables to Discord Webhook from Linux Bash Shell Script - Jason Loong | Tech Enthusiast, Photographer & Drummer](https://jasonloong.com/2018/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/)  
   
Sending Linux Variables to Discord Webhook from Linux Bash Shell Script Discord provides an API where you can send messages/notifications via their webhook using curl . Which is all very helpful, except the code provided on their website only allows plain text, you can’t pass $variables onto it Having started playing with Linux Bash scripts,…

---

<div class="post-metadata">

**Author:** ![Bryce\_Canion](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/bryce_canion/32/48_2.png) [@Bryce\_Canion](https://forums.jasonloong.com/u/Bryce_Canion)\
**Post date:** [May 17, 2020, 10:05am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/2 "2020-05-17T10:05:02Z")

</div>

used the script, works for normal messages but when I write $ commands I get this  
{“message”: “Cannot send an empty message”, “code”: 50006}

---

<div class="post-metadata">

**Author:** ![doob187](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/doob187/32/37_2.png) [@doob187](https://forums.jasonloong.com/u/doob187)\
**Post date:** [May 17, 2020, 10:08am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/3 "2020-05-17T10:08:52Z")

</div>

can you post your script ?

---

<div class="post-metadata">

**Author:** ![doob187](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/doob187/32/37_2.png) [@doob187](https://forums.jasonloong.com/u/doob187)\
**Post date:** [May 17, 2020, 10:21am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/4 "2020-05-17T10:21:36Z")

</div>

```auto
#!/bin/bash

DISCORD_WEBHOOK_URL=""
DISCORD_ICON_OVERRIDE="https://i.imgur.com/KorF8zC.png"
DISCORD_NAME_OVERRIDE="TEST-Messages"
DISCORD="/tmp/discord.discord"
###############
rm -rf "${DISCORD}" && touch "${DISCORD}"

echo "[test message] `date '+%T %A %d-%B,%Y'` status done" >"${DISCORD}"

# Send start message via Díscord
if [$DISCORD_WEBHOOK_URL != "null"]; then
   message=$(cat "${DISCORD}")
   msg_content=\"$message\"
   USERNAME=\"${DISCORD_NAME_OVERRIDE}\"
   IMAGE=\"${DISCORD_ICON_OVERRIDE}\"
   DISCORD_WEBHOOK_URL="${DISCORD_WEBHOOK_URL}"
   curl -H "Content-Type: application/json" -X POST -d "{\"username\": $USERNAME, \"avatar_url\": $IMAGE, \"content\": $msg_content}" $DISCORD_WEBHOOK_URL
 else
   echo "${output} failed"
fi

exit 0

```

if you want to send more as a one\_liner

```auto
echo "[test message] \n `date '+%T %A %d-%B,%Y'` \n status done" >"${DISCORD}"

```

 ![Screenshot1](https://forums.jasonloong.com/uploads/default/original/1X/d04b0d7512c48d88d473659b54852c336c6f5143.png)

---

<div class="post-metadata">

**Author:** ![jasonloong](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/jasonloong/32/8_2.png) [@jasonloong](https://forums.jasonloong.com/u/jasonloong)\
**Post date:** [May 17, 2020, 10:52am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/5 "2020-05-17T10:52:23Z")

</div>

Welcome to the forums @Bryce_Canion

Could you show us some code that you are trying to run so that we can further help you?

As the error implied, you sent an empty message over, which most probably indicates that the command you ran return empty or error

@doob187 thx for the quick code snippet example!

---

<div class="post-metadata">

**Author:** ![Bryce\_Canion](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/bryce_canion/32/48_2.png) [@Bryce\_Canion](https://forums.jasonloong.com/u/Bryce_Canion)\
**Post date:** [May 17, 2020, 11:01am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/8 "2020-05-17T11:01:55Z")

</div>

I used the very same script of this article, having some issues posting it

> **[Sending Linux Variables to Discord Webhook from Linux Bash Shell Script -...](https://jasonloong.com/blog/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script)**
>
> Linux bash script to send variables to Discord webhook

---

<div class="post-metadata">

**Author:** ![doob187](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/doob187/32/37_2.png) [@doob187](https://forums.jasonloong.com/u/doob187)\
**Post date:** [May 17, 2020, 11:03am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/9 "2020-05-17T11:03:48Z")

</div>

but can you show us the script ?

maybe its a simple small error ..

---

<div class="post-metadata">

**Author:** ![jasonloong](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/jasonloong/32/8_2.png) [@jasonloong](https://forums.jasonloong.com/u/jasonloong)\
**Post date:** [May 17, 2020, 11:06am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/10 "2020-05-17T11:06:07Z")

</div>

Try put this in front of your code

# ``` code here

and end it with ```

or select your code and then click on the " \</\> "

screenshot works too 🙂

---

<div class="post-metadata">

**Author:** ![Bryce\_Canion](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/bryce_canion/32/48_2.png) [@Bryce\_Canion](https://forums.jasonloong.com/u/Bryce_Canion)\
**Post date:** [May 17, 2020, 11:33am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/11 "2020-05-17T11:33:44Z")

</div>

```
#!/bin/bash
message="$@"
## format to parse to curl
## echo Sending message: $message
msg_content=\"$message\"

## discord webhook
url='https://discordapp.com/api/webhooks/urlnumbers
curl -H "Content-Type: application/json" -X POST -d "{\"content\": $msg_content}" $url

```

---

<div class="post-metadata">

**Author:** ![doob187](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/doob187/32/37_2.png) [@doob187](https://forums.jasonloong.com/u/doob187)\
**Post date:** [May 17, 2020, 11:37am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/12 "2020-05-17T11:37:09Z")

</div>

can you try 😄  
` sudo chmod a+x discord-notify.sh`

`./discord-notify.sh "[test message] `date '+%T %A %d-%B,%Y'` status done" `

---

<div class="post-metadata">

**Author:** ![Bryce\_Canion](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/bryce_canion/32/48_2.png) [@Bryce\_Canion](https://forums.jasonloong.com/u/Bryce_Canion)\
**Post date:** [May 17, 2020, 11:47am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/13 "2020-05-17T11:47:06Z")

</div>

Tried, still can send normal messages but not $ ones

---

<div class="post-metadata">

**Author:** ![jasonloong](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/jasonloong/32/8_2.png) [@jasonloong](https://forums.jasonloong.com/u/jasonloong)\
**Post date:** [May 17, 2020, 11:50am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/14 "2020-05-17T11:50:30Z")

</div>

Can you show me the full code you are trying to send including the message content?? Was it the “date” output as shown on the tutorial?

---

<div class="post-metadata">

**Author:** ![Bryce\_Canion](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/bryce_canion/32/48_2.png) [@Bryce\_Canion](https://forums.jasonloong.com/u/Bryce_Canion)\
**Post date:** [May 17, 2020, 11:59am UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/15 "2020-05-17T11:59:58Z")

</div>

Ok, skipped a thing above.  
I get the date [test mesage] 13:56:49 Domenica 17-Maggio,2020 status done like this.  
the command I’m trying to send is $dk and should be processed by another bot in the channel.  
If I put it in the [test mesage] I get nothing but

---

<div class="post-metadata">

**Author:** ![jasonloong](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/jasonloong/32/8_2.png) [@jasonloong](https://forums.jasonloong.com/u/jasonloong)\
**Post date:** [May 17, 2020, 12:04pm UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/16 "2020-05-17T12:04:30Z")

</div>

By another bot… erm… I’m not understanding, anyway, let’s check your $dk

Can you confirm that it returns the output by

`echo $dk`

---

<div class="post-metadata">

**Author:** ![Bryce\_Canion](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/bryce_canion/32/48_2.png) [@Bryce\_Canion](https://forums.jasonloong.com/u/Bryce_Canion)\
**Post date:** [May 17, 2020, 12:07pm UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/17 "2020-05-17T12:07:03Z")

</div>

I have a bot on the discord channel who takes some $commands as inputs. I want to make a script to give him some commands in sequence basically. Problem is I’m not managing to feed him those commands through this process.

Where do I write echo $dk

PS thanks for help

---

<div class="post-metadata">

**Author:** ![Bryce\_Canion](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/bryce_canion/32/48_2.png) [@Bryce\_Canion](https://forums.jasonloong.com/u/Bryce_Canion)\
**Post date:** [May 17, 2020, 12:13pm UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/18 "2020-05-17T12:13:20Z")

</div>

Oh maybe I got it wrong, sorry, and this script is supposed to work in a different way.

---

<div class="post-metadata">

**Author:** ![jasonloong](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/jasonloong/32/8_2.png) [@jasonloong](https://forums.jasonloong.com/u/jasonloong)\
**Post date:** [May 17, 2020, 12:16pm UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/19 "2020-05-17T12:16:45Z")

</div>

Ahhhhhhh I get you now

So you want to output “$dk” to your channel as it is.

We took it that you have a variable called $dk in Linux itself, not discord.

In that case you would do this to your message content:

`your_text="white space and your '$dk' message"`

You need to wrap the $dk with **Single Quotes** (not Double-Quotes), to special-escape that whole string, which is $dk

So if you only want to output “$dk” to your channel

`my_msg='$dk'`  
or  
`my_msg="'$dk'"`

Have a try at it, @doob187 tested it and it worked 🙂

Let us know if it worked out 😁

---

<div class="post-metadata">

**Author:** ![Bryce\_Canion](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/bryce_canion/32/48_2.png) [@Bryce\_Canion](https://forums.jasonloong.com/u/Bryce_Canion)\
**Post date:** [May 17, 2020, 12:25pm UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/20 "2020-05-17T12:25:32Z")

</div>

OK thanks, using only single quotes (I did not use the `my_msg=`…, is it a problem?) I can have it. Unluckily seems like the other bot doesn’t recognize it, probably because it comes from another bot. Thanks for help though  
Don’t want to bother you more, by chance do you know if I can send messages this way as user and not as bot?

---

<div class="post-metadata">

**Author:** ![jasonloong](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/jasonloong/32/8_2.png) [@jasonloong](https://forums.jasonloong.com/u/jasonloong)\
**Post date:** [May 17, 2020, 12:27pm UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/21 "2020-05-17T12:27:48Z")

</div>

> [@Bryce\_Canion](#):
>
> Don’t want to bother you more, by chance do you know if I can send messages this way as user and not as bot?

None that I know of… not a Discord expert sorry

Thanks for your time and reply anyway! 😃

---

<div class="post-metadata">

**Author:** ![doob187](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/doob187/32/37_2.png) [@doob187](https://forums.jasonloong.com/u/doob187)\
**Post date:** [May 17, 2020, 12:28pm UTC](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18/22 "2020-05-17T12:28:46Z")

</div>

you can send over this bot automatic messages

[https://github.com/doob187/docker-rsync-backup/blob/f9ede10079678d9a6d8c64df88dce97254c5dba3/backup.sh#L95](https://github.com/doob187/docker-rsync-backup/blob/f9ede10079678d9a6d8c64df88dce97254c5dba3/backup.sh#L95)

[Next page](https://forums.jasonloong.com/t/sending-linux-variables-to-discord-webhook-from-linux-bash-shell-script/18.md?page=2)
