0

I have this env file

  • 1.env contents:

    BARF_BAG=1

then another env file:

  • 2.env contents:

    BARF_BAG=2

I run comm and diff on the files to see the difference:

#!/usr/bin/env bash

(
  set -e;

  first_env_file="$1"
  second_env_file="$2"

  if ! test -f "$first_env_file"; then
     echo 'first arg must be an env file';
     exit 1;
  fi

  if ! test -f "$second_env_file"; then
     echo 'second arg must be an env file';
     exit 1;
  fi

  echo -e '\n'
  echo -e 'displaying results from diff tool:'
  diff <(. "$first_env_file"; env | sort) <(. "$second_env_file"; env | sort) || true
  echo -e '\n'
  echo 'displaying results from comm tool:'
  comm -3 <(. "$first_env_file"; env | sort ) <(. "$second_env_file"; env | sort) || true
  echo 'finished diffing env files.'
)

and I get nothing, just:

displaying results from diff tool:


displaying results from comm tool:
finished diffing env files.

what gives?

0

1 Answer 1

3

You do not seem to be running diff and comm on any files, you are comparing the output of the env command.

Since you are comparing env, the sourcing of the environment files is not doing what you expect as you would need to export the variables for them to show up in env.

Change your environment files as follows:

./1.env
export BARF_BAG=1
./2.env
export BARF_BAG=2

Now the env should be properly populated and your comparisons should output more what you were expecting.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.