Map list of filenames as option values for command

thoni56

I have a number of files and want to use their names as arguments to a command so that the command becomes

<command> <option> <file1> <option> <file2> ...

For each file name I want to prepend that with the option name. I don't know how many files there are. How can I do this? Does bash/shell have something similar to map?

The files exists so I would get the names using find, or mayb ls if I'm sure about the filenames, so I was looking for something like you can do with xargs

ls -1q <pattern> | xargs <command> ...

But instead of what xargs do (turning it into one command for each file) I want a single command with many arguments with <option> inserted before all filenames.

In my specific example I want to combine an unknown number of coverage data files with one command:

lcov -o total.coverage -a <file1> -a <file2> ... 

This is inside a Makefile, but I'd prefer a "standard" shell approach.

Philippe

Try this :

files=(pattern)
# This will expand the [pattern], and put all the files in [files] variables

lcov -o total.coverage ${files[@]/#/-a }
# ${files[@]/#/-a } replaces the beginning of each element in files with [-a ],
# meaning prepend [-a ]
# For more information, see section [${parameter/pattern/string}] in
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion

assuming you don't have special characters (like spaces) in your file names.

Este artigo é coletado da Internet.

Se houver alguma infração, entre em [email protected] Delete.

editar em
0

deixe-me dizer algumas palavras

0comentários
loginDepois de participar da revisão

Artigos relacionados

Parsing a list of values with option to empty list

Map values in list to lists by indicies

Save multiple values of a command line option in Perl array

Using List-command with variable names as values

Java - Retrive Indivudual Values from a List in a Map

Get a list of distinct values from map

Java 8 Streams: List to Map with mapped values

Groovy groupby List generated from Map values

Map values in a List based on custom Dictionary - Python

Replacing values from list of custom objects with map values

Javascript move selected option with multiple values from one list to another

Sending form input values with PHP to select an option in a list on following page

Spring Boot Thymeleaf Dropdown List option doesn't display values

Store the output of command ran on remote system and list in proper format and select the option from that list in powershell?

Optimal way to transfer values from a Map<K, V<List>> to a Map<otherKey, otherValue<List>>

Get all values for a certain key from a list of dictionaries with a single command

Nested examples in cucumber scenario outline - List or Map values

Map list elements to keys in dictionary for decimal values in python

Haskell find and replace values from list using map

moving around values around in a list using map plus function

How to send form field values in libcurl ? (the one that uses -F option in command line curl)

Converting List[Option[A]] to an Option[List[A]] in Scala

Select/Option values as NULL

Flutter MethodChannel nested values: 'List<dynamic>' is not a subtype of type 'FutureOr<List<Map<String, double>>>'

Compare scala map values to a list and return default value for keys that don't exist in the list

Filter Map of Map of List

Option -l of exec shell command

Terraform Output linux command option?

Terraform Output linux command option?

TOP lista

  1. 1

    R Shiny: use HTML em funções (como textInput, checkboxGroupInput)

  2. 2

    O Chromium e o Firefox exibem as cores de maneira diferente e não sei qual deles está fazendo certo

  3. 3

    Como assinar digitalmente um documento PDF com assinatura e texto visíveis usando Java

  4. 4

    R Folheto. Dados de pontos de grupo em células para resumir muitos pontos de dados

  5. 5

    Gerenciar recurso shake de Windows Aero com barra de título personalizado

  6. 6

    Como obter dados API adequados para o aplicativo angular?

  7. 7

    UITextView não está exibindo texto longo

  8. 8

    Por que meus intervalos de confiança de 95% da minha regressão multivariada estão sendo plotados como uma linha de loess?

  9. 9

    Acessando relatório de campanhas na AdMob usando a API do Adsense

  10. 10

    Usando o plug-in Platform.js do Google

  11. 11

    Como posso modificar esse algoritmo de linha de visada para aceitar raios que passam pelos cantos?

  12. 12

    Dependência circular de diálogo personalizado

  13. 13

    Coloque uma caixa de texto HTML em uma imagem em uma posição fixa para site para desktop e celular

  14. 14

    iOS: como adicionar sombra projetada e sombra de traço no UIView?

  15. 15

    Como usar a caixa de diálogo de seleção de nomes com VBA para enviar e-mail para mais de um destinatário?

  16. 16

    Tabela CSS: barra de rolagem para a primeira coluna e largura automática para a coluna restante

  17. 17

    How to create dynamic navigation menu select from database using Codeigniter?

  18. 18

    Converter valores de linha SQL em colunas

  19. 19

    ChartJS, várias linhas no rótulo do gráfico de barras

  20. 20

    用@StyleableRes注释的getStyledAttributes。禁止警告

  21. 21

    não é possível adicionar dependência para com.google.android.gms.tasks.OnSuccessListener

quentelabel

Arquivo