aws cli s3 sync: how to exclude multiple files2019 Community Moderator ElectionHow do I parse command line arguments in Bash?How to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How can I exclude all “permission denied” messages from “find”?How can I redirect and append both stdout and stderr to a file with Bash?How do I split a string on a delimiter in Bash?How to count all the lines of code in a directory recursively?How do I reload .bashrc without logging out and back in?How to concatenate string variables in Bash

Are all passive ability checks floors for active ability checks?

What are substitutions for coconut in curry?

how to write formula in word in latex

Did Ender ever learn that he killed Stilson and/or Bonzo?

How to make healing in an exploration game interesting

Are ETF trackers fundamentally better than individual stocks?

Do the common programs (for example: "ls", "cat") in Linux and BSD come from the same source code?

What is the significance behind "40 days" that often appears in the Bible?

How to write cleanly even if my character uses expletive language?

How do I hide Chekhov's Gun?

Does Mathematica reuse previous computations?

Life insurance that covers only simultaneous/dual deaths

Unexpected result from ArcLength

Is it possible to upcast ritual spells?

Why do Australian milk farmers need to protest supermarkets' milk price?

Why is the President allowed to veto a cancellation of emergency powers?

Look at your watch and tell me what time is it. vs Look at your watch and tell me what time it is

A link redirect to http instead of https: how critical is it?

Python if-else code style for reduced code for rounding floats

How to terminate ping <dest> &

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible

Min function accepting varying number of arguments in C++17

Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?

Why doesn't the EU now just force the UK to choose between referendum and no-deal?



aws cli s3 sync: how to exclude multiple files



2019 Community Moderator ElectionHow do I parse command line arguments in Bash?How to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How can I exclude all “permission denied” messages from “find”?How can I redirect and append both stdout and stderr to a file with Bash?How do I split a string on a delimiter in Bash?How to count all the lines of code in a directory recursively?How do I reload .bashrc without logging out and back in?How to concatenate string variables in Bash










0















So I have a bash script which deletes all contents from an AWS S3 bucket and then uploads the contents of a local folder to that same bucket.



#!/bin/bash

# deploy to s3
function deploy()
aws s3 rm s3://bucketname --profile Administrator --recursive
aws s3 sync ./ s3://bucketname --profile Administrator --exclude='node_modules/*' --exclude='.git/*' --exclude='clickCounter.py' --exclude='package-lock.json' --exclude='bundle.js.map' --exclude='package.json' --exclude='webpack_dev_server.js' --exclude='.vscode/*' --exclude='.DS_Store'


deploy


However - as you can see, I have quite a few files to be excluded, and this list may increase in the future.



So my question: Is there a way I can just put the files to be excluded into an array and then iterate over that?



Perhaps something like:



#!/bin/bash

arrayOfExcludedItems = (node_modules/* package-lock.json bundle.js.map )

# deploy to s3
function deploy()
aws s3 rm s3://bucketname --profile Administrator --recursive
aws s3 sync ./ s3://bucketname --profile Administrator for item in arrayOfExcludedItems --exclude


deploy









share|improve this question




























    0















    So I have a bash script which deletes all contents from an AWS S3 bucket and then uploads the contents of a local folder to that same bucket.



    #!/bin/bash

    # deploy to s3
    function deploy()
    aws s3 rm s3://bucketname --profile Administrator --recursive
    aws s3 sync ./ s3://bucketname --profile Administrator --exclude='node_modules/*' --exclude='.git/*' --exclude='clickCounter.py' --exclude='package-lock.json' --exclude='bundle.js.map' --exclude='package.json' --exclude='webpack_dev_server.js' --exclude='.vscode/*' --exclude='.DS_Store'


    deploy


    However - as you can see, I have quite a few files to be excluded, and this list may increase in the future.



    So my question: Is there a way I can just put the files to be excluded into an array and then iterate over that?



    Perhaps something like:



    #!/bin/bash

    arrayOfExcludedItems = (node_modules/* package-lock.json bundle.js.map )

    # deploy to s3
    function deploy()
    aws s3 rm s3://bucketname --profile Administrator --recursive
    aws s3 sync ./ s3://bucketname --profile Administrator for item in arrayOfExcludedItems --exclude


    deploy









    share|improve this question


























      0












      0








      0








      So I have a bash script which deletes all contents from an AWS S3 bucket and then uploads the contents of a local folder to that same bucket.



      #!/bin/bash

      # deploy to s3
      function deploy()
      aws s3 rm s3://bucketname --profile Administrator --recursive
      aws s3 sync ./ s3://bucketname --profile Administrator --exclude='node_modules/*' --exclude='.git/*' --exclude='clickCounter.py' --exclude='package-lock.json' --exclude='bundle.js.map' --exclude='package.json' --exclude='webpack_dev_server.js' --exclude='.vscode/*' --exclude='.DS_Store'


      deploy


      However - as you can see, I have quite a few files to be excluded, and this list may increase in the future.



      So my question: Is there a way I can just put the files to be excluded into an array and then iterate over that?



      Perhaps something like:



      #!/bin/bash

      arrayOfExcludedItems = (node_modules/* package-lock.json bundle.js.map )

      # deploy to s3
      function deploy()
      aws s3 rm s3://bucketname --profile Administrator --recursive
      aws s3 sync ./ s3://bucketname --profile Administrator for item in arrayOfExcludedItems --exclude


      deploy









      share|improve this question
















      So I have a bash script which deletes all contents from an AWS S3 bucket and then uploads the contents of a local folder to that same bucket.



      #!/bin/bash

      # deploy to s3
      function deploy()
      aws s3 rm s3://bucketname --profile Administrator --recursive
      aws s3 sync ./ s3://bucketname --profile Administrator --exclude='node_modules/*' --exclude='.git/*' --exclude='clickCounter.py' --exclude='package-lock.json' --exclude='bundle.js.map' --exclude='package.json' --exclude='webpack_dev_server.js' --exclude='.vscode/*' --exclude='.DS_Store'


      deploy


      However - as you can see, I have quite a few files to be excluded, and this list may increase in the future.



      So my question: Is there a way I can just put the files to be excluded into an array and then iterate over that?



      Perhaps something like:



      #!/bin/bash

      arrayOfExcludedItems = (node_modules/* package-lock.json bundle.js.map )

      # deploy to s3
      function deploy()
      aws s3 rm s3://bucketname --profile Administrator --recursive
      aws s3 sync ./ s3://bucketname --profile Administrator for item in arrayOfExcludedItems --exclude


      deploy






      bash amazon-s3 aws-cli






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 14:11







      Filtenborg

















      asked Mar 7 at 13:52









      FiltenborgFiltenborg

      14239




      14239






















          1 Answer
          1






          active

          oldest

          votes


















          3














          You can't use a loop in the middle of an argument list, but you can do a textual substitution adding "--exclude=" to the beginning of each element. First, though, you must declare the array correctly; that means no spaces around the =, and you need to quote any entries that contain wildcards (that you don't want expanded on the spot):



          arrayOfExcludedItems=('node_modules/*' '.git/*' clickCounter.py package-lock.json 
          bundle.js.map package.json webpack_dev_server.js '.vscode/*' .DS_Store)


          Then use the array like this:



          aws s3 sync ./ s3://bucketname --profile Administrator 
          "$arrayOfExcludedItems[@]/#/--exclude="


          How it works: the [@] tells the shell to get all elements of the array (treating each as a separate word), the /#a/b part tells it to replace a at the beginning of each element with b, but a is empty so it effectively just adds "--exclude=" to the beginning. Oh, and the double-quotes around it tells the shell not to expand wildcards or otherwise mess with the results.






          share|improve this answer

























          • Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir

            – Filtenborg
            Mar 7 at 21:26











          • The /#a/b is very cool. I had no idea you could use it to transform an array.

            – Alex Harvey
            Mar 8 at 8:41










          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%2f55045423%2faws-cli-s3-sync-how-to-exclude-multiple-files%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









          3














          You can't use a loop in the middle of an argument list, but you can do a textual substitution adding "--exclude=" to the beginning of each element. First, though, you must declare the array correctly; that means no spaces around the =, and you need to quote any entries that contain wildcards (that you don't want expanded on the spot):



          arrayOfExcludedItems=('node_modules/*' '.git/*' clickCounter.py package-lock.json 
          bundle.js.map package.json webpack_dev_server.js '.vscode/*' .DS_Store)


          Then use the array like this:



          aws s3 sync ./ s3://bucketname --profile Administrator 
          "$arrayOfExcludedItems[@]/#/--exclude="


          How it works: the [@] tells the shell to get all elements of the array (treating each as a separate word), the /#a/b part tells it to replace a at the beginning of each element with b, but a is empty so it effectively just adds "--exclude=" to the beginning. Oh, and the double-quotes around it tells the shell not to expand wildcards or otherwise mess with the results.






          share|improve this answer

























          • Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir

            – Filtenborg
            Mar 7 at 21:26











          • The /#a/b is very cool. I had no idea you could use it to transform an array.

            – Alex Harvey
            Mar 8 at 8:41















          3














          You can't use a loop in the middle of an argument list, but you can do a textual substitution adding "--exclude=" to the beginning of each element. First, though, you must declare the array correctly; that means no spaces around the =, and you need to quote any entries that contain wildcards (that you don't want expanded on the spot):



          arrayOfExcludedItems=('node_modules/*' '.git/*' clickCounter.py package-lock.json 
          bundle.js.map package.json webpack_dev_server.js '.vscode/*' .DS_Store)


          Then use the array like this:



          aws s3 sync ./ s3://bucketname --profile Administrator 
          "$arrayOfExcludedItems[@]/#/--exclude="


          How it works: the [@] tells the shell to get all elements of the array (treating each as a separate word), the /#a/b part tells it to replace a at the beginning of each element with b, but a is empty so it effectively just adds "--exclude=" to the beginning. Oh, and the double-quotes around it tells the shell not to expand wildcards or otherwise mess with the results.






          share|improve this answer

























          • Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir

            – Filtenborg
            Mar 7 at 21:26











          • The /#a/b is very cool. I had no idea you could use it to transform an array.

            – Alex Harvey
            Mar 8 at 8:41













          3












          3








          3







          You can't use a loop in the middle of an argument list, but you can do a textual substitution adding "--exclude=" to the beginning of each element. First, though, you must declare the array correctly; that means no spaces around the =, and you need to quote any entries that contain wildcards (that you don't want expanded on the spot):



          arrayOfExcludedItems=('node_modules/*' '.git/*' clickCounter.py package-lock.json 
          bundle.js.map package.json webpack_dev_server.js '.vscode/*' .DS_Store)


          Then use the array like this:



          aws s3 sync ./ s3://bucketname --profile Administrator 
          "$arrayOfExcludedItems[@]/#/--exclude="


          How it works: the [@] tells the shell to get all elements of the array (treating each as a separate word), the /#a/b part tells it to replace a at the beginning of each element with b, but a is empty so it effectively just adds "--exclude=" to the beginning. Oh, and the double-quotes around it tells the shell not to expand wildcards or otherwise mess with the results.






          share|improve this answer















          You can't use a loop in the middle of an argument list, but you can do a textual substitution adding "--exclude=" to the beginning of each element. First, though, you must declare the array correctly; that means no spaces around the =, and you need to quote any entries that contain wildcards (that you don't want expanded on the spot):



          arrayOfExcludedItems=('node_modules/*' '.git/*' clickCounter.py package-lock.json 
          bundle.js.map package.json webpack_dev_server.js '.vscode/*' .DS_Store)


          Then use the array like this:



          aws s3 sync ./ s3://bucketname --profile Administrator 
          "$arrayOfExcludedItems[@]/#/--exclude="


          How it works: the [@] tells the shell to get all elements of the array (treating each as a separate word), the /#a/b part tells it to replace a at the beginning of each element with b, but a is empty so it effectively just adds "--exclude=" to the beginning. Oh, and the double-quotes around it tells the shell not to expand wildcards or otherwise mess with the results.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 11 at 2:42









          Alex Harvey

          5,2661923




          5,2661923










          answered Mar 7 at 15:23









          Gordon DavissonGordon Davisson

          70.3k97894




          70.3k97894












          • Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir

            – Filtenborg
            Mar 7 at 21:26











          • The /#a/b is very cool. I had no idea you could use it to transform an array.

            – Alex Harvey
            Mar 8 at 8:41

















          • Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir

            – Filtenborg
            Mar 7 at 21:26











          • The /#a/b is very cool. I had no idea you could use it to transform an array.

            – Alex Harvey
            Mar 8 at 8:41
















          Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir

          – Filtenborg
          Mar 7 at 21:26





          Perfect! just what i was looking for! Love the explanation of how the code works, thanks a bunch good sir

          – Filtenborg
          Mar 7 at 21:26













          The /#a/b is very cool. I had no idea you could use it to transform an array.

          – Alex Harvey
          Mar 8 at 8:41





          The /#a/b is very cool. I had no idea you could use it to transform an array.

          – Alex Harvey
          Mar 8 at 8:41



















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55045423%2faws-cli-s3-sync-how-to-exclude-multiple-files%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

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme