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

243
Visualizações
How can I make a bash string of command with redirect and pipe?

I want to make a bash string of commands with redirect and/or pipe, and use it to either display the string of commands or execute the string of commands. A simple command without redirect or pipe works, but a string of commands with redirect or pipe does not. For example,

command="echo 1"
$command
echo "$command"

would display

1
echo 1

However,

command="echo 1 | cat"
$command
echo "$command"

would display

1 | cat
echo 1 | cat

but, I want

1
echo 1 | cat

Similarly for redirect,

command="echo 1 | cat > 1.out"
$command
echo "$command"

would display

1 | cat > 1.out
echo 1 | cat > 1.out

but I want

echo 1 | cat > 1.out

with a new file named "1.out" with content 1 in it.

Is there a way to achieve what I want?

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

0

If you want the shell to evaluate the string as a command, tell it to do so with eval:

eval "$command"
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