我想将curl结果作为参数传递给另一个脚本,即脚本delete-app.sh
#!/bin/sh
SERVICE_HOST=localhost
SERVICE_PORT=9200
delete(){
echo "entered here"
if [ $# -lt 2 ]; then
echo "usage: $0 delete [--name] [index_name]"
exit 1
fi
case "$1" in
--name)
index_name=$2
;;
*)
echo "Unknown argument $1"
exit 1
;;
esac
echo $index_name
}
if [ $# -eq 0 ]; then
echo "Usage: $0 (delete)"
exit 1
fi
case "$1" in
delete)
delete $2 $3
;;
*)
echo "Unknown argument $1"
exit 1
;;
esac
exit 0运行以下命令
./delete_app.sh delete --name `curl -s "http://<host>:<port>/_cat/indices/applicationevent*" | awk -F ' ' '{print $3}' | cut -c18- | awk -v d=`date -d'10 days ago' +'%Y.%m.%d'` -F'|' '$1 < d' | awk '{print "applicationevent-" $1 }' |paste -s -d, -在这里,我为--name获得的参数来自curl命令结果,但现在结果并不存在。
发布于 2021-03-17 13:56:28
下面的方法运行良好。
./delete_app.sh delete --name $(curl -s "http://<host>:<port>/_cat/indices/applicationevent*" | awk -F ' ' '{print $3}' | cut -c18- | awk -v d=`date -d'10 days ago' +'%Y.%m.%d'` -F'|' '$1 < d' | awk '{print "applicationevent-" $1 }' |paste -s -d, -)https://stackoverflow.com/questions/66667639
复制相似问题