我可以使用以下命令执行单独的 cURL 命令:
curl -u user:password -v -XPOST -H 'Content-type: text/xml' -d '<featureType><name>quadrella_indica</name></featureType>' http://localhost:8080/geoserver/rest/workspaces/opengeo/datastores/species/featuretypes
但我需要循环遍历 shp 文件的整个列表,所以,
for f in *.shp
do
a=${f,,};
curl -u user:password -v -XPOST -H 'Content-type: text/xml' -d '<featureType><name>${a%.*}</name></featureType>' http://localhost:8080/geoserver/rest/workspaces/opengeo/datastores/species/featuretypes
done
但与我单独添加它们时收到的成功不同,当我循环时收到错误,
* About to connect() to localhost port 8080 (#0)
* Trying ::1... connected
* Server auth using Basic with user 'admin'
> POST /geoserver/rest/workspaces/opengeo/datastores/species/featuretypes HTTP/1.1
> Authorization: Basic YWRtaW46Z2Vvc2VydmVy
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: localhost:8080
> Accept: */*
> Content-type: text/xml
> Content-Length: 47
>
* upload completely sent off: 47out of 47 bytes
< HTTP/1.1 400 Bad Request
< Server: Apache-Coyote/1.1
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Date: Sun, 25 Nov 2012 18:19:31 GMT
< Connection: close
<
* Closing connection #0
Trying to create new feature type inside the store, but no attributes were specified
我在循环中做错了一些事情,因为各个 cURL 工作得很好。我怎样才能纠正它?
答案1
变量不在单引号内展开,而是使用双引号:
curl ... "...${var%.*}..."