I am trying to write a bash script to update certain nodes in my repository. I wrote below script, but it does not seem to be working when I use variables inside curl
. Below is the code. I tried all possible combinations using ""
inside curl
statement to resolve the variable. But it does not seem to update the nodes. (I don't get any error when running the script).
I echo'ed the curl
line like:
echo "curl --user admin:admin "$final_add" http://localhost:4502"$a""
and placed its output in the script, then the script runs fine and updated the node.
Can anyone provide me some guidance on why cant i update the nodes using the variables in curl.
Code Sample Below
#!/bin/bash echo "-------------------------------------------------------------------------------------------------------------------" echo "Script to set tags" echo "-------------------------------------------------------------------------------------------------------------------" if [ true ] then echo "**firing curl command for tags2**" a="/content/test/events/whats-on/all-about-women-home/2018/wine-tasting/jcr:content" i="[/content/cq:tags/sales-stage/pre-sale,/content/cq:tags/sales-stage/special-offer]" str=$i IFS=, ary=($str) for key in "${!ary[@]}"; do tags_paths+="-Ftags2=${ary[$key]} "; done final_paths=$(echo $tags_paths | sed "s|[2],]||g") final_add="-Ftags2@TypeHint=\"String[]\" ${final_paths//[[[\[\]]/}" #have tried this without quotes too --eg : (curl --user admin:admin $final_add http://localhost:4502$a) it too didnt work curl --user admin:admin "$final_add" http://localhost:4502"$a" fi
"$final_add"
is passed tocurl
as one argument, containing-Ftags2@TypeHint="String[]" -Ftags2=/content/cq:tags/sales-stage/pre-sale -Ftags2=/content/cq:tags/sales-stage/special-offer
. Is this what you want?curl -v
option to know the network request details.