如何在bash方法中将参数传递给curl命令
我有一个执行curl命令的方法,它返回结果。我想将参数传递给此方法,但它不起作用如何在bash方法中将参数传递给curl命令,bash,function,curl,Bash,Function,Curl,我有一个执行curl命令的方法,它返回结果。我想将参数传递给此方法,但它不起作用 commande_mine() { local MY_OUTPUT=$(curl -X POST \ http://localhost:5000/myapp \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -d '{ "filepath": "$1" }') echo
commande_mine() {
local MY_OUTPUT=$(curl -X POST \
http://localhost:5000/myapp \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"filepath": "$1"
}')
echo $MY_OUTPUT
}
for f in "/Users/anthony/my files"/*
do
commande_mine $f >> test.txt
break # break first time until everything works as expected
done
如何使用传入curl命令内函数的$f参数?您可以使用:
commande_mine() {
local MY_OUTPUT=$(curl -X POST \
http://localhost:5000/myapp \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"filepath": "'"$1"'"
}')
echo "$MY_OUTPUT"
}
并称之为:
for f in "/Users/anthony/my files"/*
do
commande_mine "$f"
break
done > test.txt