“Linux Source Env File” Kode Jawaban

Linux Source Env File


set -a
. ./env.txt
set +a
DreamCoder

Linux Source Env File

# allows you to have empty lines for better readability
eval $(cat .env | sed 's/^/export /')

# Here is another sed solution, which does not run eval or require ruby:
source <(sed -E -n 's/[^#]+/export &/ p' ~/.env)

  # .env contents
  A=1
  #B=2

  # sample run
  $ sed -E -n 's/[^#]+/export &/ p' ~/.env
  export A=1
  #export B=2
DreamCoder

Linux Source Env File


export $(xargs < .env)

# Explanation
# When we have a .env file like this:

key=val
foo=bar
DreamCoder

Linux Source Env File

# export.sh .env

set -a # export all variables created next
source $1
set +a # stop exporting
DreamCoder

Linux Source Env File

# To ignore lines that start with #, use this (thanks to Pete's comment):
export $(grep -v '^#' .env | xargs)

# And if you want to unset all of the variables defined in the file, use this:
unset $(grep -v '^#' .env | sed -E 's/(.*)=.*/\1/' | xargs)
DreamCoder

Linux Source Env File

# convenience command to prepend export to the beginning of
awk '{print "export " $0}' envfile 
DreamCoder

Jawaban yang mirip dengan “Linux Source Env File”

Pertanyaan yang mirip dengan “Linux Source Env File”

Lebih banyak jawaban terkait untuk “Linux Source Env File” di Shell/Bash

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya