Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
Running a command after a command that used xargs and fswatch

Hi I am trying to write a shell command that does:

  1. watch a folder
  2. when a file has changed copy that new file somewhere
  3. then runs a make task

fswatch ./src | xargs -I {} cp {} ./otherfolder

the first 2 things are working with the command above, but I cannot figure out how to run a command after this.

I've tried

fswatch ./src | xargs -I {} cp {} ./otherfolder && make

That doesn't work because the && are conflicting with xargs I think

fswatch ./src | xargs -I {} cp {} ./otherfolder | make

Here the make command is immediately called, not after the copying is done. (It's even called before fswatch triggers on a change)

Is it possible to run a command after the cp using xargs?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

One way to solve the problem would be to spawn a shell:

fswatch  ./src | xargs -I {} sh -c "cp '{}' ./otherfolder && make"

The contents of the double quotes are executed in a separate shell and will behave as you expect (first the copy, then the execution of make, assuming the copy was successful).

The single quotes around {} are advised to guard against problems when the filename contains spaces or other characters such as * which would otherwise be expanded by the shell.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda