Bash: Iterating 2 lists using single For In loopWhat is the meaning of IFS=$'n' in bash scripting?Read files...

Security vulnerabilities of POST over SSL

Why was this character made Grand Maester?

Popcorn is the only acceptable snack to consume while watching a movie

How to deal with a colleague who is being aggressive?

Dad jokes are fun

Why did Jon Snow do this immoral act if he is so honorable?

Can a person survive on blood in place of water?

Time complexity of an algorithm: Is it important to state the base of the logarithm?

What is the use case for non-breathable waterproof pants?

Why isn't Tyrion mentioned in the in-universe book "A Song of Ice and Fire"?

Did 20% of US soldiers in Vietnam use heroin, 95% of whom quit afterwards?

How to politely tell someone they did not hit "reply to all" in an email?

Did this character show any indication of wanting to rule before S8E6?

My players want to grind XP but we're using milestone advancement

Why did the person in charge of a principality not just declare themself king?

Determine this limit

Can my floppy disk still work without a shutter spring?

What's difference between "depends on" and "is blocked by" relations between issues in Jira next-gen board?

Gravitational effects of a single human body on the motion of planets

Can you output map values in visualforce inline using a string key?

Where is Jon going?

Count all vowels in string

Shorten or merge multiple lines of `&> /dev/null &`

Why do Russians almost not use verbs of possession akin to "have"?



Bash: Iterating 2 lists using single For In loop


What is the meaning of IFS=$'n' in bash scripting?Read files in Directory and take diffCat 2 files and avoid duplication of linesbash script loses readonly value after first time thru loopParse two files input in for/while loop'Tar' the result of a 'find', preserving the directory structureComparing each file in two directories and copying it to another if it differs from its counterpartComparing 2 directories and copying the different sub-directories to a 3rd directoryHow to write output to a file of the same name as the input?How do I run a diff of short file names?for loop to prepend dir name to file names






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















Suppose I have 2 seperate loops



for file1 in `ls Dir1/` ; do
echo $file1
done

for file2 in `ls Dir2/` ; do
echo $file2
done


I want Single loop to iterate both Directories
pseudocode



for file1 , file2 in `ls Dir1` , `ls Dir2`
do
echo $file1
echo file2
done


Is it possible










share|improve this question























  • you cant do that, but you could use a function that takes the dir as a parameter and iterates through its files.

    – jai_s
    Feb 12 '16 at 16:44











  • if you explain what actually you are trying to do, instead of a code which does nothing significant, may be you can get a different suggestion than looping through two directories in a single for loop. Just a thought.

    – MelBurslan
    Feb 12 '16 at 16:47











  • I want to iterate files of 2 directories 1 by 1

    – Muhammad Danish
    Feb 12 '16 at 16:48











  • dir1 has many files dir2 has many files I want to work on file1 from dir1 and file1 from dir2 and so on

    – Muhammad Danish
    Feb 12 '16 at 16:49


















2















Suppose I have 2 seperate loops



for file1 in `ls Dir1/` ; do
echo $file1
done

for file2 in `ls Dir2/` ; do
echo $file2
done


I want Single loop to iterate both Directories
pseudocode



for file1 , file2 in `ls Dir1` , `ls Dir2`
do
echo $file1
echo file2
done


Is it possible










share|improve this question























  • you cant do that, but you could use a function that takes the dir as a parameter and iterates through its files.

    – jai_s
    Feb 12 '16 at 16:44











  • if you explain what actually you are trying to do, instead of a code which does nothing significant, may be you can get a different suggestion than looping through two directories in a single for loop. Just a thought.

    – MelBurslan
    Feb 12 '16 at 16:47











  • I want to iterate files of 2 directories 1 by 1

    – Muhammad Danish
    Feb 12 '16 at 16:48











  • dir1 has many files dir2 has many files I want to work on file1 from dir1 and file1 from dir2 and so on

    – Muhammad Danish
    Feb 12 '16 at 16:49














2












2








2








Suppose I have 2 seperate loops



for file1 in `ls Dir1/` ; do
echo $file1
done

for file2 in `ls Dir2/` ; do
echo $file2
done


I want Single loop to iterate both Directories
pseudocode



for file1 , file2 in `ls Dir1` , `ls Dir2`
do
echo $file1
echo file2
done


Is it possible










share|improve this question














Suppose I have 2 seperate loops



for file1 in `ls Dir1/` ; do
echo $file1
done

for file2 in `ls Dir2/` ; do
echo $file2
done


I want Single loop to iterate both Directories
pseudocode



for file1 , file2 in `ls Dir1` , `ls Dir2`
do
echo $file1
echo file2
done


Is it possible







linux bash shell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 12 '16 at 16:41









Muhammad DanishMuhammad Danish

134




134













  • you cant do that, but you could use a function that takes the dir as a parameter and iterates through its files.

    – jai_s
    Feb 12 '16 at 16:44











  • if you explain what actually you are trying to do, instead of a code which does nothing significant, may be you can get a different suggestion than looping through two directories in a single for loop. Just a thought.

    – MelBurslan
    Feb 12 '16 at 16:47











  • I want to iterate files of 2 directories 1 by 1

    – Muhammad Danish
    Feb 12 '16 at 16:48











  • dir1 has many files dir2 has many files I want to work on file1 from dir1 and file1 from dir2 and so on

    – Muhammad Danish
    Feb 12 '16 at 16:49



















  • you cant do that, but you could use a function that takes the dir as a parameter and iterates through its files.

    – jai_s
    Feb 12 '16 at 16:44











  • if you explain what actually you are trying to do, instead of a code which does nothing significant, may be you can get a different suggestion than looping through two directories in a single for loop. Just a thought.

    – MelBurslan
    Feb 12 '16 at 16:47











  • I want to iterate files of 2 directories 1 by 1

    – Muhammad Danish
    Feb 12 '16 at 16:48











  • dir1 has many files dir2 has many files I want to work on file1 from dir1 and file1 from dir2 and so on

    – Muhammad Danish
    Feb 12 '16 at 16:49

















you cant do that, but you could use a function that takes the dir as a parameter and iterates through its files.

– jai_s
Feb 12 '16 at 16:44





you cant do that, but you could use a function that takes the dir as a parameter and iterates through its files.

– jai_s
Feb 12 '16 at 16:44













if you explain what actually you are trying to do, instead of a code which does nothing significant, may be you can get a different suggestion than looping through two directories in a single for loop. Just a thought.

– MelBurslan
Feb 12 '16 at 16:47





if you explain what actually you are trying to do, instead of a code which does nothing significant, may be you can get a different suggestion than looping through two directories in a single for loop. Just a thought.

– MelBurslan
Feb 12 '16 at 16:47













I want to iterate files of 2 directories 1 by 1

– Muhammad Danish
Feb 12 '16 at 16:48





I want to iterate files of 2 directories 1 by 1

– Muhammad Danish
Feb 12 '16 at 16:48













dir1 has many files dir2 has many files I want to work on file1 from dir1 and file1 from dir2 and so on

– Muhammad Danish
Feb 12 '16 at 16:49





dir1 has many files dir2 has many files I want to work on file1 from dir1 and file1 from dir2 and so on

– Muhammad Danish
Feb 12 '16 at 16:49










2 Answers
2






active

oldest

votes


















2














A while loop with suitable input can do the job, assuming no IFS-thwarting characters in the directory listings.



paste <(ls /var) <(ls /usr) | while read e u; do echo $e $u; done





share|improve this answer
























  • Thank you Can you tell me what is IFS-thwarting characters or you can give me link

    – Muhammad Danish
    Feb 12 '16 at 16:50








  • 1





    I got it what is meant by IFS unix.stackexchange.com/questions/184863/…

    – Muhammad Danish
    Feb 12 '16 at 16:55



















0














The output of multiple variables can be saved in single variable as mentioned below one. Check if it works for you



#!/bin/bash
cd /
for file1 in $(ls /usr/ ; echo "::::::NEXT:::::::" ; ls /sys/)
do
echo $file1
done




share
























    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f261828%2fbash-iterating-2-lists-using-single-for-in-loop%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    A while loop with suitable input can do the job, assuming no IFS-thwarting characters in the directory listings.



    paste <(ls /var) <(ls /usr) | while read e u; do echo $e $u; done





    share|improve this answer
























    • Thank you Can you tell me what is IFS-thwarting characters or you can give me link

      – Muhammad Danish
      Feb 12 '16 at 16:50








    • 1





      I got it what is meant by IFS unix.stackexchange.com/questions/184863/…

      – Muhammad Danish
      Feb 12 '16 at 16:55
















    2














    A while loop with suitable input can do the job, assuming no IFS-thwarting characters in the directory listings.



    paste <(ls /var) <(ls /usr) | while read e u; do echo $e $u; done





    share|improve this answer
























    • Thank you Can you tell me what is IFS-thwarting characters or you can give me link

      – Muhammad Danish
      Feb 12 '16 at 16:50








    • 1





      I got it what is meant by IFS unix.stackexchange.com/questions/184863/…

      – Muhammad Danish
      Feb 12 '16 at 16:55














    2












    2








    2







    A while loop with suitable input can do the job, assuming no IFS-thwarting characters in the directory listings.



    paste <(ls /var) <(ls /usr) | while read e u; do echo $e $u; done





    share|improve this answer













    A while loop with suitable input can do the job, assuming no IFS-thwarting characters in the directory listings.



    paste <(ls /var) <(ls /usr) | while read e u; do echo $e $u; done






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 12 '16 at 16:47









    thrigthrig

    25.5k23660




    25.5k23660













    • Thank you Can you tell me what is IFS-thwarting characters or you can give me link

      – Muhammad Danish
      Feb 12 '16 at 16:50








    • 1





      I got it what is meant by IFS unix.stackexchange.com/questions/184863/…

      – Muhammad Danish
      Feb 12 '16 at 16:55



















    • Thank you Can you tell me what is IFS-thwarting characters or you can give me link

      – Muhammad Danish
      Feb 12 '16 at 16:50








    • 1





      I got it what is meant by IFS unix.stackexchange.com/questions/184863/…

      – Muhammad Danish
      Feb 12 '16 at 16:55

















    Thank you Can you tell me what is IFS-thwarting characters or you can give me link

    – Muhammad Danish
    Feb 12 '16 at 16:50







    Thank you Can you tell me what is IFS-thwarting characters or you can give me link

    – Muhammad Danish
    Feb 12 '16 at 16:50






    1




    1





    I got it what is meant by IFS unix.stackexchange.com/questions/184863/…

    – Muhammad Danish
    Feb 12 '16 at 16:55





    I got it what is meant by IFS unix.stackexchange.com/questions/184863/…

    – Muhammad Danish
    Feb 12 '16 at 16:55













    0














    The output of multiple variables can be saved in single variable as mentioned below one. Check if it works for you



    #!/bin/bash
    cd /
    for file1 in $(ls /usr/ ; echo "::::::NEXT:::::::" ; ls /sys/)
    do
    echo $file1
    done




    share




























      0














      The output of multiple variables can be saved in single variable as mentioned below one. Check if it works for you



      #!/bin/bash
      cd /
      for file1 in $(ls /usr/ ; echo "::::::NEXT:::::::" ; ls /sys/)
      do
      echo $file1
      done




      share


























        0












        0








        0







        The output of multiple variables can be saved in single variable as mentioned below one. Check if it works for you



        #!/bin/bash
        cd /
        for file1 in $(ls /usr/ ; echo "::::::NEXT:::::::" ; ls /sys/)
        do
        echo $file1
        done




        share













        The output of multiple variables can be saved in single variable as mentioned below one. Check if it works for you



        #!/bin/bash
        cd /
        for file1 in $(ls /usr/ ; echo "::::::NEXT:::::::" ; ls /sys/)
        do
        echo $file1
        done





        share











        share


        share










        answered 3 mins ago









        linux.cnflinux.cnf

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • 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%2funix.stackexchange.com%2fquestions%2f261828%2fbash-iterating-2-lists-using-single-for-in-loop%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

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...