如何在 curl 命令中将 bash 变量用于 @filepath

如何在 curl 命令中将 bash 变量用于 @filepath

我正在尝试编写一个 bash 脚本来运行一系列 curl 命令。我尝试运行的命令如下:

curl -XPUT $URL'/test/' -d @$DATA_DIR/index-settings.json

这是我的 bash 脚本

#!/bin/bash
set -e

DATA_DIR="/usr/local/es"
URL="http://localhost:9200"

curl -XPUT $URL'/test/' -d @$DATA_DIR/index-settings.json

我已经确认,如果我像这样手动运行该命令,它将有效:

curl -XPUT 'http://localhost:9200/test/' -d @/usr/local/es/index-settings.json

问题出在 $DATA_DIR 上。当我使用 $DATA_DIR 变量运行 bash 脚本时,出现此错误:

Warning: Couldn't read data from file 
Warning: "/usr/local/es/index-settings.json", this makes 
Warning: an empty POST.

是否可以在使用 -d @ 参数的 curl 命令中使用变量?

相关内容