How to run more than one command in the powershell?

Asked

Viewed 1,018 times

2

I have the following command of AWS Cli that runs on Windows Powershell and downloads a specific folder inside a S3 Bucket:

 aws s3 cp s3://rfcarga/RF73 . --recursive

But I have other collections of images to download too, follows example:

aws s3 cp s3://rfcarga/RF73 . --recursive
aws s3 cp s3://rfcarga/RF73A . --recursive
aws s3 cp s3://rfcarga/RF73Ba . --recursive
aws s3 cp s3://rfcarga/RF73Bb . --recursive
aws s3 cp s3://rfcarga/RF73Ca . --recursive
aws s3 cp s3://rfcarga/RF73Cb . --recursive
aws s3 cp s3://rfcarga/RF73D . --recursive

I would not like to run one by one but all in one ENTER, as I run several commands one after the other at once in Powershell?

  • Maybe, aws S3 cp S3://rfcarga/RF73*

1 answer

2


Can use a array and pass it to the command to execute:

@("RF73", "RF73A", ...) | % { aws s3 cp s3://rfcarga/$_ . --recursive }

In this example, we create a array with the name of the images to be downloaded and we pass each element of the array, through the |, at the loop operator %.

This operator will execute the code between the {} for each element in array and refers to the value used in this iteration through the $_.

Note:

If you simply want to have multiple expressions on the same line, you can separate each expression with a ;:

aws s3 cp s3://rfcarga/RF73 . --recursive; aws s3 cp s3://rfcarga/RF73A . --recursive
  • 1

    Perfect Omni, I liked the option too much with array !

  • @Leonardobonetti is great. If you understand the concept, you can now improve the line to better fit your case (example: read the names of the files to download from a file and pass the content in the same way I show in the answer (Get-Content 'caminho ficheiro' | % {...} )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.