bash - 传递的参数不会在 curl 命令中解释
问题描述
我有一个 shell 脚本,它只执行 curl 命令来通知我的 Discord 服务器有关问题。我传递了两个参数,我想将它们添加到 curl 命令的数据体中,但它们的值不会被解释。
我的脚本调用:
./notifier.sh usernameArg contentArg
我的脚本:
#!/bin/bash
curl -X POST -H "Content-Type: application/json" -d '{"username": "$1", "content": "$2"}' "https://<discord webhook url>"
但它发送的只是{"username": "$1", "content": "$2"}
. 我还尝试使用 ${1} 和 ${2} 获得相同的结果。
提前感谢您的帮助!
解决方案
试试这个。
#!/bin/bash
curl -X POST -H "Content-Type: application/json" -d '{"username": "'$1'", "content": "'$2'"}' "https://<discord webhook url>"
推荐阅读
- delphi - 项目版本设置不断恢复
- html - 用漂亮的汤解析表返回非类型对象
- react-native - 反应本机 numberOfLines 样式问题
- python - 如何从python在sqlite中插入表
- android - Main Activity 总是第一个启动的 Activity 吗?
- android - 无法使用 ProGuard 实例化 AndroidPlatform 类
- ios - CallKit/Voip:呼叫者句柄如何被阻塞?
- mysql - .Net Core - MySqlException:无法添加或更新子行
- if-statement - Arrayformula 两个单元格的加法
- r - 为什么 dplyr::case_when 在尝试从 setNames 引用列名时会中断