Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda