BASH scripting - not the expected output?









up vote
1
down vote

favorite












Hi I have here two text files, boy.txt and girl.txt



the values from boy.txt are:



12345678
87654321


the values from girl.txt are:



35f1f125-5d33-44a4-82fc-26734843c804
5abd0360-c4be-4e69-8085-340755f87290


I have to use these two values inside curl command, this is my command:



readarray boy < boy.txt
readarray girl < girl.txt

count=0
for i in $girl[@]
do
result[$boy[$count]]=$i
count=$((count+1))

for output1 in $!result[@]; do
output2=$result[$output1];


echo "curl -X PUT
--header "Content-Type: application/json"
--header "Accept: application/json"
--header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid- cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
-d "\""referenceId:"$output2"\""" "https://website.com:443/testing/api/devices/"$output1"/parentPath" " > test.sh

done
done

chmod+x test.sh

./test.sh


The output from command above is:



problem is only one curl command gets echoed instead of two



curl -X PUT 
--header "Content-Type: application/json"
--header "Accept: application/json"
--header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
-d ""referenceId:35f1f125-5d33-44a4-82fc-26734843c804"" "https://webite.com:443/testing/api/devices/12345678/parentPath"


My expected output:



echo the command in an .sh file



curl -X PUT 
--header "Content-Type: application/json"
--header "Accept: application/json"
--header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
-d ""referenceId:35f1f125-5d33-44a4-82fc-26734843c804"" "https://webite.com:443/testing/api/devices/12345678/parentPath"


curl -X PUT
--header "Content-Type: application/json"
--header "Accept: application/json"
--header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
-d ""referenceId:5abd0360-c4be-4e69-8085-340755f87290"" "https://webite.com:443/testing/api/devices/87654321/parentPath"


Or if you have a way (right syntax) so that I can curl directly, much appreciated.










share|improve this question

























    up vote
    1
    down vote

    favorite












    Hi I have here two text files, boy.txt and girl.txt



    the values from boy.txt are:



    12345678
    87654321


    the values from girl.txt are:



    35f1f125-5d33-44a4-82fc-26734843c804
    5abd0360-c4be-4e69-8085-340755f87290


    I have to use these two values inside curl command, this is my command:



    readarray boy < boy.txt
    readarray girl < girl.txt

    count=0
    for i in $girl[@]
    do
    result[$boy[$count]]=$i
    count=$((count+1))

    for output1 in $!result[@]; do
    output2=$result[$output1];


    echo "curl -X PUT
    --header "Content-Type: application/json"
    --header "Accept: application/json"
    --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid- cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
    -d "\""referenceId:"$output2"\""" "https://website.com:443/testing/api/devices/"$output1"/parentPath" " > test.sh

    done
    done

    chmod+x test.sh

    ./test.sh


    The output from command above is:



    problem is only one curl command gets echoed instead of two



    curl -X PUT 
    --header "Content-Type: application/json"
    --header "Accept: application/json"
    --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
    -d ""referenceId:35f1f125-5d33-44a4-82fc-26734843c804"" "https://webite.com:443/testing/api/devices/12345678/parentPath"


    My expected output:



    echo the command in an .sh file



    curl -X PUT 
    --header "Content-Type: application/json"
    --header "Accept: application/json"
    --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
    -d ""referenceId:35f1f125-5d33-44a4-82fc-26734843c804"" "https://webite.com:443/testing/api/devices/12345678/parentPath"


    curl -X PUT
    --header "Content-Type: application/json"
    --header "Accept: application/json"
    --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
    -d ""referenceId:5abd0360-c4be-4e69-8085-340755f87290"" "https://webite.com:443/testing/api/devices/87654321/parentPath"


    Or if you have a way (right syntax) so that I can curl directly, much appreciated.










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Hi I have here two text files, boy.txt and girl.txt



      the values from boy.txt are:



      12345678
      87654321


      the values from girl.txt are:



      35f1f125-5d33-44a4-82fc-26734843c804
      5abd0360-c4be-4e69-8085-340755f87290


      I have to use these two values inside curl command, this is my command:



      readarray boy < boy.txt
      readarray girl < girl.txt

      count=0
      for i in $girl[@]
      do
      result[$boy[$count]]=$i
      count=$((count+1))

      for output1 in $!result[@]; do
      output2=$result[$output1];


      echo "curl -X PUT
      --header "Content-Type: application/json"
      --header "Accept: application/json"
      --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid- cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
      -d "\""referenceId:"$output2"\""" "https://website.com:443/testing/api/devices/"$output1"/parentPath" " > test.sh

      done
      done

      chmod+x test.sh

      ./test.sh


      The output from command above is:



      problem is only one curl command gets echoed instead of two



      curl -X PUT 
      --header "Content-Type: application/json"
      --header "Accept: application/json"
      --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
      -d ""referenceId:35f1f125-5d33-44a4-82fc-26734843c804"" "https://webite.com:443/testing/api/devices/12345678/parentPath"


      My expected output:



      echo the command in an .sh file



      curl -X PUT 
      --header "Content-Type: application/json"
      --header "Accept: application/json"
      --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
      -d ""referenceId:35f1f125-5d33-44a4-82fc-26734843c804"" "https://webite.com:443/testing/api/devices/12345678/parentPath"


      curl -X PUT
      --header "Content-Type: application/json"
      --header "Accept: application/json"
      --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
      -d ""referenceId:5abd0360-c4be-4e69-8085-340755f87290"" "https://webite.com:443/testing/api/devices/87654321/parentPath"


      Or if you have a way (right syntax) so that I can curl directly, much appreciated.










      share|improve this question













      Hi I have here two text files, boy.txt and girl.txt



      the values from boy.txt are:



      12345678
      87654321


      the values from girl.txt are:



      35f1f125-5d33-44a4-82fc-26734843c804
      5abd0360-c4be-4e69-8085-340755f87290


      I have to use these two values inside curl command, this is my command:



      readarray boy < boy.txt
      readarray girl < girl.txt

      count=0
      for i in $girl[@]
      do
      result[$boy[$count]]=$i
      count=$((count+1))

      for output1 in $!result[@]; do
      output2=$result[$output1];


      echo "curl -X PUT
      --header "Content-Type: application/json"
      --header "Accept: application/json"
      --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid- cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
      -d "\""referenceId:"$output2"\""" "https://website.com:443/testing/api/devices/"$output1"/parentPath" " > test.sh

      done
      done

      chmod+x test.sh

      ./test.sh


      The output from command above is:



      problem is only one curl command gets echoed instead of two



      curl -X PUT 
      --header "Content-Type: application/json"
      --header "Accept: application/json"
      --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
      -d ""referenceId:35f1f125-5d33-44a4-82fc-26734843c804"" "https://webite.com:443/testing/api/devices/12345678/parentPath"


      My expected output:



      echo the command in an .sh file



      curl -X PUT 
      --header "Content-Type: application/json"
      --header "Accept: application/json"
      --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
      -d ""referenceId:35f1f125-5d33-44a4-82fc-26734843c804"" "https://webite.com:443/testing/api/devices/12345678/parentPath"


      curl -X PUT
      --header "Content-Type: application/json"
      --header "Accept: application/json"
      --header "Authorization: Bearer gAAAAJ1EY28EHByJCcgT-sWhzid-cxW1uQrfO1QJG52D4n9GYj9YWd4KUGBSxO2LXZ48eEbQivSAlM6bplNE82o84UFnkwiVJ0V1q4DM9VAHw6jU4UvkdhhSrlupC6gKl_RHEgf2cluwvAN11My7eFflA-JnBrINp02d146CaJrR_r52hAEAAIAAAAAXmL1IDoHPz3S5deta0ygANUUoEFBsuKHaeDo3NXVUptxxDXR00yaNmILqd1psJckYhrBhh7wdQNdNYaSsqgwsF8Nuw_hhUAbg27hhGaVLmbeK3eS3mtVlq1D73Vg3KSk-24DmR0o-jT2u88k4MLfkqxuipEsLAEcSoe4zAPE1jcch2GGvlNWTHN98gMxw-svmvu6hizZ1fe-pWNtMGwa9u_hVimOr8A-7HcidA4Sj_jBprulGUapifc-Dd_qZFj1FM1HedHvnu8NKzp_uRr8z_Myk0IO6RyqjPPufLdafV3N4hmEqVex8P8jr4SkZWT0f-4i1epfZcRJmz6ognOCfaxa91c3qFNpG3IVY881g9aCPdLOxmU5FqKDPgHIZLvp8wWeTWdi_YQaAXMUh-yZQXBLhBimG8SR2iRj6ZTvu_L_Ytmc0QePkaijA6CB8wY2SbHlOGL2JUcEXKoNjC9dSSbkHqWx0tXMR2XCCdlhHPC1vGYcCgV-XQ_bfqgN7yn8"
      -d ""referenceId:5abd0360-c4be-4e69-8085-340755f87290"" "https://webite.com:443/testing/api/devices/87654321/parentPath"


      Or if you have a way (right syntax) so that I can curl directly, much appreciated.







      bash curl echo counter






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 2:01









      Confidential Company

      83




      83






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Use >> instead of > when you want to append rather that overwrite.



          ..."$output1"/parentPath" " > test.sh


          Should be



          ..."$output1"/parentPath" " >> test.sh


          Edit: I think you can use something a little simpler than what you are doing:



          #!/bin/bash

          while read -r boy && read -r girl <&3; do
          # I omitted parts of the curl command with ...
          echo "curl -X PUT ... referenceId:$girl ...api/devices/$boy/" >> test.sh

          done < boy.txt 3<girl.txt





          share|improve this answer






















          • Hi ssemilla, your great! after I've followed your answer, it echoed about 3xcurl-command (first second third). im not sure why. I only need two output. any ideas?
            – Confidential Company
            Nov 11 at 4:07










          • Well that is because you have an inner loop and based from the logic of your script, you will really have three outputs.
            – ssemilla
            Nov 11 at 4:45










          • @ConfidentialCompany look at the updated code, your problem could be solved a little bit easier by reading the two files in the same loop.
            – ssemilla
            Nov 11 at 4:57










          • It works! thanks
            – Confidential Company
            Nov 11 at 13:43










          • Note that you probably need/want to remove any old copy of the output file in the top of the script (before the loop). Otherwise, if you run it more than once, you'll keep appending to the same file. Alternately, do the output redirect as >test.sh on the done line with your simplified example.
            – Chris Dodd
            Nov 11 at 17:07











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245208%2fbash-scripting-not-the-expected-output%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Use >> instead of > when you want to append rather that overwrite.



          ..."$output1"/parentPath" " > test.sh


          Should be



          ..."$output1"/parentPath" " >> test.sh


          Edit: I think you can use something a little simpler than what you are doing:



          #!/bin/bash

          while read -r boy && read -r girl <&3; do
          # I omitted parts of the curl command with ...
          echo "curl -X PUT ... referenceId:$girl ...api/devices/$boy/" >> test.sh

          done < boy.txt 3<girl.txt





          share|improve this answer






















          • Hi ssemilla, your great! after I've followed your answer, it echoed about 3xcurl-command (first second third). im not sure why. I only need two output. any ideas?
            – Confidential Company
            Nov 11 at 4:07










          • Well that is because you have an inner loop and based from the logic of your script, you will really have three outputs.
            – ssemilla
            Nov 11 at 4:45










          • @ConfidentialCompany look at the updated code, your problem could be solved a little bit easier by reading the two files in the same loop.
            – ssemilla
            Nov 11 at 4:57










          • It works! thanks
            – Confidential Company
            Nov 11 at 13:43










          • Note that you probably need/want to remove any old copy of the output file in the top of the script (before the loop). Otherwise, if you run it more than once, you'll keep appending to the same file. Alternately, do the output redirect as >test.sh on the done line with your simplified example.
            – Chris Dodd
            Nov 11 at 17:07















          up vote
          1
          down vote



          accepted










          Use >> instead of > when you want to append rather that overwrite.



          ..."$output1"/parentPath" " > test.sh


          Should be



          ..."$output1"/parentPath" " >> test.sh


          Edit: I think you can use something a little simpler than what you are doing:



          #!/bin/bash

          while read -r boy && read -r girl <&3; do
          # I omitted parts of the curl command with ...
          echo "curl -X PUT ... referenceId:$girl ...api/devices/$boy/" >> test.sh

          done < boy.txt 3<girl.txt





          share|improve this answer






















          • Hi ssemilla, your great! after I've followed your answer, it echoed about 3xcurl-command (first second third). im not sure why. I only need two output. any ideas?
            – Confidential Company
            Nov 11 at 4:07










          • Well that is because you have an inner loop and based from the logic of your script, you will really have three outputs.
            – ssemilla
            Nov 11 at 4:45










          • @ConfidentialCompany look at the updated code, your problem could be solved a little bit easier by reading the two files in the same loop.
            – ssemilla
            Nov 11 at 4:57










          • It works! thanks
            – Confidential Company
            Nov 11 at 13:43










          • Note that you probably need/want to remove any old copy of the output file in the top of the script (before the loop). Otherwise, if you run it more than once, you'll keep appending to the same file. Alternately, do the output redirect as >test.sh on the done line with your simplified example.
            – Chris Dodd
            Nov 11 at 17:07













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Use >> instead of > when you want to append rather that overwrite.



          ..."$output1"/parentPath" " > test.sh


          Should be



          ..."$output1"/parentPath" " >> test.sh


          Edit: I think you can use something a little simpler than what you are doing:



          #!/bin/bash

          while read -r boy && read -r girl <&3; do
          # I omitted parts of the curl command with ...
          echo "curl -X PUT ... referenceId:$girl ...api/devices/$boy/" >> test.sh

          done < boy.txt 3<girl.txt





          share|improve this answer














          Use >> instead of > when you want to append rather that overwrite.



          ..."$output1"/parentPath" " > test.sh


          Should be



          ..."$output1"/parentPath" " >> test.sh


          Edit: I think you can use something a little simpler than what you are doing:



          #!/bin/bash

          while read -r boy && read -r girl <&3; do
          # I omitted parts of the curl command with ...
          echo "curl -X PUT ... referenceId:$girl ...api/devices/$boy/" >> test.sh

          done < boy.txt 3<girl.txt






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 17:00

























          answered Nov 11 at 3:29









          ssemilla

          3,077424




          3,077424











          • Hi ssemilla, your great! after I've followed your answer, it echoed about 3xcurl-command (first second third). im not sure why. I only need two output. any ideas?
            – Confidential Company
            Nov 11 at 4:07










          • Well that is because you have an inner loop and based from the logic of your script, you will really have three outputs.
            – ssemilla
            Nov 11 at 4:45










          • @ConfidentialCompany look at the updated code, your problem could be solved a little bit easier by reading the two files in the same loop.
            – ssemilla
            Nov 11 at 4:57










          • It works! thanks
            – Confidential Company
            Nov 11 at 13:43










          • Note that you probably need/want to remove any old copy of the output file in the top of the script (before the loop). Otherwise, if you run it more than once, you'll keep appending to the same file. Alternately, do the output redirect as >test.sh on the done line with your simplified example.
            – Chris Dodd
            Nov 11 at 17:07

















          • Hi ssemilla, your great! after I've followed your answer, it echoed about 3xcurl-command (first second third). im not sure why. I only need two output. any ideas?
            – Confidential Company
            Nov 11 at 4:07










          • Well that is because you have an inner loop and based from the logic of your script, you will really have three outputs.
            – ssemilla
            Nov 11 at 4:45










          • @ConfidentialCompany look at the updated code, your problem could be solved a little bit easier by reading the two files in the same loop.
            – ssemilla
            Nov 11 at 4:57










          • It works! thanks
            – Confidential Company
            Nov 11 at 13:43










          • Note that you probably need/want to remove any old copy of the output file in the top of the script (before the loop). Otherwise, if you run it more than once, you'll keep appending to the same file. Alternately, do the output redirect as >test.sh on the done line with your simplified example.
            – Chris Dodd
            Nov 11 at 17:07
















          Hi ssemilla, your great! after I've followed your answer, it echoed about 3xcurl-command (first second third). im not sure why. I only need two output. any ideas?
          – Confidential Company
          Nov 11 at 4:07




          Hi ssemilla, your great! after I've followed your answer, it echoed about 3xcurl-command (first second third). im not sure why. I only need two output. any ideas?
          – Confidential Company
          Nov 11 at 4:07












          Well that is because you have an inner loop and based from the logic of your script, you will really have three outputs.
          – ssemilla
          Nov 11 at 4:45




          Well that is because you have an inner loop and based from the logic of your script, you will really have three outputs.
          – ssemilla
          Nov 11 at 4:45












          @ConfidentialCompany look at the updated code, your problem could be solved a little bit easier by reading the two files in the same loop.
          – ssemilla
          Nov 11 at 4:57




          @ConfidentialCompany look at the updated code, your problem could be solved a little bit easier by reading the two files in the same loop.
          – ssemilla
          Nov 11 at 4:57












          It works! thanks
          – Confidential Company
          Nov 11 at 13:43




          It works! thanks
          – Confidential Company
          Nov 11 at 13:43












          Note that you probably need/want to remove any old copy of the output file in the top of the script (before the loop). Otherwise, if you run it more than once, you'll keep appending to the same file. Alternately, do the output redirect as >test.sh on the done line with your simplified example.
          – Chris Dodd
          Nov 11 at 17:07





          Note that you probably need/want to remove any old copy of the output file in the top of the script (before the loop). Otherwise, if you run it more than once, you'll keep appending to the same file. Alternately, do the output redirect as >test.sh on the done line with your simplified example.
          – Chris Dodd
          Nov 11 at 17:07


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245208%2fbash-scripting-not-the-expected-output%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo