loop over files to pass as arguments to a script

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











up vote
0
down vote

favorite
1












I have a script some.sh that loops over several files;



#!/bin/bash
path_to_destin ="/some/path/"
path_to_raw ="some/other/path"
list = "001 002 003"
for l in $list
do
mkdir $path_to_destin/output_$l
python somescript.py -input $path_to_raw/dir_$l -output $path_to_destin/output_$l/table_$l.txt
done


This script generates three files table_001.q, table_002.q and table_003.q.



After the loop, another script take as input these files,



some_other_script -i table_001.q -i table_002.q -i table_003.q -o all.q


Is there a way to run as many -i table_*** as it is indicated in $list?







share|improve this question

























    up vote
    0
    down vote

    favorite
    1












    I have a script some.sh that loops over several files;



    #!/bin/bash
    path_to_destin ="/some/path/"
    path_to_raw ="some/other/path"
    list = "001 002 003"
    for l in $list
    do
    mkdir $path_to_destin/output_$l
    python somescript.py -input $path_to_raw/dir_$l -output $path_to_destin/output_$l/table_$l.txt
    done


    This script generates three files table_001.q, table_002.q and table_003.q.



    After the loop, another script take as input these files,



    some_other_script -i table_001.q -i table_002.q -i table_003.q -o all.q


    Is there a way to run as many -i table_*** as it is indicated in $list?







    share|improve this question























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      I have a script some.sh that loops over several files;



      #!/bin/bash
      path_to_destin ="/some/path/"
      path_to_raw ="some/other/path"
      list = "001 002 003"
      for l in $list
      do
      mkdir $path_to_destin/output_$l
      python somescript.py -input $path_to_raw/dir_$l -output $path_to_destin/output_$l/table_$l.txt
      done


      This script generates three files table_001.q, table_002.q and table_003.q.



      After the loop, another script take as input these files,



      some_other_script -i table_001.q -i table_002.q -i table_003.q -o all.q


      Is there a way to run as many -i table_*** as it is indicated in $list?







      share|improve this question













      I have a script some.sh that loops over several files;



      #!/bin/bash
      path_to_destin ="/some/path/"
      path_to_raw ="some/other/path"
      list = "001 002 003"
      for l in $list
      do
      mkdir $path_to_destin/output_$l
      python somescript.py -input $path_to_raw/dir_$l -output $path_to_destin/output_$l/table_$l.txt
      done


      This script generates three files table_001.q, table_002.q and table_003.q.



      After the loop, another script take as input these files,



      some_other_script -i table_001.q -i table_002.q -i table_003.q -o all.q


      Is there a way to run as many -i table_*** as it is indicated in $list?









      share|improve this question












      share|improve this question




      share|improve this question








      edited May 9 at 14:26









      ilkkachu

      48.1k669133




      48.1k669133









      asked May 9 at 13:59









      user3037937

      83




      83




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          #!/bin/bash

          indir='/some/other/path'
          outdir='/some/path'

          list=( 001 002 003 )

          for i in "$list[@]"; do
          mkdir -p "$outdir/output_$i"
          python somescript.py -input "$indir/dir_$i" -output "$outdir/output_$i/table_$i.txt"

          inargs+=( -i "table_$i.q" )
          done

          some_other_script "$inargs[@]" -o all.q


          Observations:



          1. Assignments may not have space around =.

          2. Indentation and whitespace improves readability.

          3. Don't loop over strings, loop over arrays.

          4. Quote all variable expansions.

          Regarding quoting of variable expansions:



          • Security implications of forgetting to quote a variable in bash/POSIX shells

          • Why does my shell script choke on whitespace or other special characters?





          share|improve this answer





















          • Thank you for your input and the solution, really helpful!
            – user3037937
            May 9 at 15:56










          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%2f442778%2floop-over-files-to-pass-as-arguments-to-a-script%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



          accepted










          #!/bin/bash

          indir='/some/other/path'
          outdir='/some/path'

          list=( 001 002 003 )

          for i in "$list[@]"; do
          mkdir -p "$outdir/output_$i"
          python somescript.py -input "$indir/dir_$i" -output "$outdir/output_$i/table_$i.txt"

          inargs+=( -i "table_$i.q" )
          done

          some_other_script "$inargs[@]" -o all.q


          Observations:



          1. Assignments may not have space around =.

          2. Indentation and whitespace improves readability.

          3. Don't loop over strings, loop over arrays.

          4. Quote all variable expansions.

          Regarding quoting of variable expansions:



          • Security implications of forgetting to quote a variable in bash/POSIX shells

          • Why does my shell script choke on whitespace or other special characters?





          share|improve this answer





















          • Thank you for your input and the solution, really helpful!
            – user3037937
            May 9 at 15:56














          up vote
          2
          down vote



          accepted










          #!/bin/bash

          indir='/some/other/path'
          outdir='/some/path'

          list=( 001 002 003 )

          for i in "$list[@]"; do
          mkdir -p "$outdir/output_$i"
          python somescript.py -input "$indir/dir_$i" -output "$outdir/output_$i/table_$i.txt"

          inargs+=( -i "table_$i.q" )
          done

          some_other_script "$inargs[@]" -o all.q


          Observations:



          1. Assignments may not have space around =.

          2. Indentation and whitespace improves readability.

          3. Don't loop over strings, loop over arrays.

          4. Quote all variable expansions.

          Regarding quoting of variable expansions:



          • Security implications of forgetting to quote a variable in bash/POSIX shells

          • Why does my shell script choke on whitespace or other special characters?





          share|improve this answer





















          • Thank you for your input and the solution, really helpful!
            – user3037937
            May 9 at 15:56












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          #!/bin/bash

          indir='/some/other/path'
          outdir='/some/path'

          list=( 001 002 003 )

          for i in "$list[@]"; do
          mkdir -p "$outdir/output_$i"
          python somescript.py -input "$indir/dir_$i" -output "$outdir/output_$i/table_$i.txt"

          inargs+=( -i "table_$i.q" )
          done

          some_other_script "$inargs[@]" -o all.q


          Observations:



          1. Assignments may not have space around =.

          2. Indentation and whitespace improves readability.

          3. Don't loop over strings, loop over arrays.

          4. Quote all variable expansions.

          Regarding quoting of variable expansions:



          • Security implications of forgetting to quote a variable in bash/POSIX shells

          • Why does my shell script choke on whitespace or other special characters?





          share|improve this answer













          #!/bin/bash

          indir='/some/other/path'
          outdir='/some/path'

          list=( 001 002 003 )

          for i in "$list[@]"; do
          mkdir -p "$outdir/output_$i"
          python somescript.py -input "$indir/dir_$i" -output "$outdir/output_$i/table_$i.txt"

          inargs+=( -i "table_$i.q" )
          done

          some_other_script "$inargs[@]" -o all.q


          Observations:



          1. Assignments may not have space around =.

          2. Indentation and whitespace improves readability.

          3. Don't loop over strings, loop over arrays.

          4. Quote all variable expansions.

          Regarding quoting of variable expansions:



          • Security implications of forgetting to quote a variable in bash/POSIX shells

          • Why does my shell script choke on whitespace or other special characters?






          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered May 9 at 14:12









          Kusalananda

          102k13199315




          102k13199315











          • Thank you for your input and the solution, really helpful!
            – user3037937
            May 9 at 15:56
















          • Thank you for your input and the solution, really helpful!
            – user3037937
            May 9 at 15:56















          Thank you for your input and the solution, really helpful!
          – user3037937
          May 9 at 15:56




          Thank you for your input and the solution, really helpful!
          – user3037937
          May 9 at 15:56












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442778%2floop-over-files-to-pass-as-arguments-to-a-script%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?