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

406
Visualizações
Running shell script using .env file

I am fairly new to running scripts in UNIX/Linux. I have a .env file containing environment information and a .sh script containing folder creations etc for that environment.

How would I run the script on the environment contained in the .env file or how could I point the script to the target environment?

Would it be as easy as:

bash 'scriptname.sh' 'filename.env'
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

You need to source the environment in the calling shell before starting the script:

source 'filename.env' && bash 'scriptname.sh'

In order to prevent polution of the environment of the calling shell you might run that in a sub shell:

(source 'filename.env' && bash 'scriptname.sh')
over 4 years ago · Santiago Trujillo Relatório

0

. ./filename.env 
sh scriptname.sh

First command set the env. variables in the shell, second one will use it to execute itself.

over 4 years ago · Santiago Trujillo Relatório

0

Create the a file with name maybe run_with_env.sh with below content

ENV_FILE="$1"
CMD=${@:2}

set -o allexport
source $ENV_FILE
set +o allexport

$CMD

Change the permission to 755

chmod 755 run_with_env.sh

Now run the bash file with below command

./run_with_env.sh filename.env sh scriptname.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