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

183
Vistas
Command Not Found when assigning an integer variable from another script

To illustrate my issue and questions consider two scripts.

Script1.sh

#!/bin/sh
test=1
echo $test

Script2.sh

#!/bin/sh
$(Script1.sh)

When I run Script1.sh from the command line directly via ./Script1.sh it produces the desired output.

1

However when I run Script2.sh which calls Script1.sh, instead I get the following error message:

Script2.sh: line 1: 1: command not found

It thinks that the integer 1 is a command for some odd reason?

I found a cheap work around which is to set a variable from the first script and pass it to the second script as a parameter but I would like to understand why this is failing.

Also, when I changed my variables value from 1 to "some text", I would expect that my echo would print "some text" to the screen. But when I call Script2.sh (which ultimately just calls Script1.sh) it doesn't print the echo to the screen. Why is that, and how do I resolve it so I can see the echo output the same as if I would have called Script1.sh directly?

Any advice would be greatly appreciated.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You're calling it wrong by using command substitution. Just use source or a subshell if you want it:

. ./Script1.sh
( ./Script1.sh )

The second one is a bit redundant since it will always run in another shell anyway, so this would make more sense instead:

( . ./Script1.sh )
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