How do I redirect output to a variable file name in a for loop?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












How do I redirect output to a variable file name in a for loop?



This doesn't work:



for ((j=501; j <=550; j++)); do 
curl -x http://us-wa.proxymesh.com:31280 "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000" >trial_$j_out.html 2> trial_$j_error.txt;
done


I keep on having trial_.html and trial_.txt written.







share|improve this question
















  • 3




    Because you have no j_out or j_error variable defined. Just replace trial_$j_out.html and trial_$j_error.txt with trial_$j_out.html and trial_$j_error.txt.
    – user2233709
    Oct 21 '17 at 11:26















up vote
0
down vote

favorite












How do I redirect output to a variable file name in a for loop?



This doesn't work:



for ((j=501; j <=550; j++)); do 
curl -x http://us-wa.proxymesh.com:31280 "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000" >trial_$j_out.html 2> trial_$j_error.txt;
done


I keep on having trial_.html and trial_.txt written.







share|improve this question
















  • 3




    Because you have no j_out or j_error variable defined. Just replace trial_$j_out.html and trial_$j_error.txt with trial_$j_out.html and trial_$j_error.txt.
    – user2233709
    Oct 21 '17 at 11:26













up vote
0
down vote

favorite









up vote
0
down vote

favorite











How do I redirect output to a variable file name in a for loop?



This doesn't work:



for ((j=501; j <=550; j++)); do 
curl -x http://us-wa.proxymesh.com:31280 "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000" >trial_$j_out.html 2> trial_$j_error.txt;
done


I keep on having trial_.html and trial_.txt written.







share|improve this question












How do I redirect output to a variable file name in a for loop?



This doesn't work:



for ((j=501; j <=550; j++)); do 
curl -x http://us-wa.proxymesh.com:31280 "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000" >trial_$j_out.html 2> trial_$j_error.txt;
done


I keep on having trial_.html and trial_.txt written.









share|improve this question











share|improve this question




share|improve this question










asked Oct 21 '17 at 11:22









humanitiesclinic

3912




3912







  • 3




    Because you have no j_out or j_error variable defined. Just replace trial_$j_out.html and trial_$j_error.txt with trial_$j_out.html and trial_$j_error.txt.
    – user2233709
    Oct 21 '17 at 11:26













  • 3




    Because you have no j_out or j_error variable defined. Just replace trial_$j_out.html and trial_$j_error.txt with trial_$j_out.html and trial_$j_error.txt.
    – user2233709
    Oct 21 '17 at 11:26








3




3




Because you have no j_out or j_error variable defined. Just replace trial_$j_out.html and trial_$j_error.txt with trial_$j_out.html and trial_$j_error.txt.
– user2233709
Oct 21 '17 at 11:26





Because you have no j_out or j_error variable defined. Just replace trial_$j_out.html and trial_$j_error.txt with trial_$j_out.html and trial_$j_error.txt.
– user2233709
Oct 21 '17 at 11:26











1 Answer
1






active

oldest

votes

















up vote
2
down vote













As pointed out in comments, _ is a valid character in a variable name. The shell will interpret trial_$j_out.html and trial_$j_error.txt as consisting of text surrounding the variables $j_out and $j_error.



Use $j instead, just like you (needlessly) did in the actual URL:



for (( j=501; j<=550; j++ )); do 
curl -x http://us-wa.proxymesh.com:31280
"https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000"
>"trial_$j_out.html" 2>"trial_$j_error.txt"
done


This will properly delimit the name of the variable from the following _. The $j in the URL does not need curly braces as the character & is not valid as part of a variable name.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399524%2fhow-do-i-redirect-output-to-a-variable-file-name-in-a-for-loop%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    As pointed out in comments, _ is a valid character in a variable name. The shell will interpret trial_$j_out.html and trial_$j_error.txt as consisting of text surrounding the variables $j_out and $j_error.



    Use $j instead, just like you (needlessly) did in the actual URL:



    for (( j=501; j<=550; j++ )); do 
    curl -x http://us-wa.proxymesh.com:31280
    "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000"
    >"trial_$j_out.html" 2>"trial_$j_error.txt"
    done


    This will properly delimit the name of the variable from the following _. The $j in the URL does not need curly braces as the character & is not valid as part of a variable name.






    share|improve this answer
























      up vote
      2
      down vote













      As pointed out in comments, _ is a valid character in a variable name. The shell will interpret trial_$j_out.html and trial_$j_error.txt as consisting of text surrounding the variables $j_out and $j_error.



      Use $j instead, just like you (needlessly) did in the actual URL:



      for (( j=501; j<=550; j++ )); do 
      curl -x http://us-wa.proxymesh.com:31280
      "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000"
      >"trial_$j_out.html" 2>"trial_$j_error.txt"
      done


      This will properly delimit the name of the variable from the following _. The $j in the URL does not need curly braces as the character & is not valid as part of a variable name.






      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        As pointed out in comments, _ is a valid character in a variable name. The shell will interpret trial_$j_out.html and trial_$j_error.txt as consisting of text surrounding the variables $j_out and $j_error.



        Use $j instead, just like you (needlessly) did in the actual URL:



        for (( j=501; j<=550; j++ )); do 
        curl -x http://us-wa.proxymesh.com:31280
        "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000"
        >"trial_$j_out.html" 2>"trial_$j_error.txt"
        done


        This will properly delimit the name of the variable from the following _. The $j in the URL does not need curly braces as the character & is not valid as part of a variable name.






        share|improve this answer












        As pointed out in comments, _ is a valid character in a variable name. The shell will interpret trial_$j_out.html and trial_$j_error.txt as consisting of text surrounding the variables $j_out and $j_error.



        Use $j instead, just like you (needlessly) did in the actual URL:



        for (( j=501; j<=550; j++ )); do 
        curl -x http://us-wa.proxymesh.com:31280
        "https://catalog.loc.gov/vwebv/search?searchArg=D$j&searchCode=CALL%2B&searchType=1&limitTo=none&fromYear=&toYear=&limitTo=LOCA%3Dall&limitTo=PLAC%3Dall&limitTo=TYPE%3Dall&limitTo=LANG%3Dall&recCount=1000"
        >"trial_$j_out.html" 2>"trial_$j_error.txt"
        done


        This will properly delimit the name of the variable from the following _. The $j in the URL does not need curly braces as the character & is not valid as part of a variable name.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 21 '17 at 11:59









        Kusalananda

        105k14209326




        105k14209326



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399524%2fhow-do-i-redirect-output-to-a-variable-file-name-in-a-for-loop%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?