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

184
Visualizações
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 Respostas
Responde à pergunta

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 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