Please, consider the script below. It checks two environments to see if both have equal sets of env variables names. The problem starts on the line of second grep. If files Ds1 and Ps1 are the same, Du is not produced at all. The first grep however produces an empty Pu file.
Another strange thing. If I run the script with ./script the problem occurs, if I use bash script, both grep lines behave identically producing two empty files.
Any explanation? How can I make them run the same way regardless of invocation method?
#!/bin/bash -e
# Script name, added to console prints
action="\e[32m"${0}"\e[39m"
exit_code=0
echo -e ${action}": Start of script."
echo
#get var names from both files
awk '{print $1}' Ds > Ds1
awk '{print $1}' Ps > Ps1
# Get vars not in Dev
grep -Fxvf Ds1 Ps1 > Pu
# Get vars not in Prod
grep -Fxvf Ps1 Ds1 > Du
# If there are vars unique to Dev, print them
if [ -s Du ]; then
echo -e ${action}": List of env variables unique to Dev:"
echo
while read p; do
cat Ds | grep $p
done < Du
echo
exit_code=1
fi
# If there are vars unique to Prod, print them
if [ -s Pu ]; then
echo -e ${action}": List of env variables unique to Prod:"
while read line; do
cat Ps | grep $line
done < Pu
exit_code=1
fi
exit ${exit_code}
Here is a part of Ds1 file if needed:
AMBURAPP_ACCESS_TOKEN
AWS_ACCESS_KEY_ID
AWS_DB_BACKUP_REGION
AWS_DB_BACKUP_S3_BUCKET_NAME
AWS_SECRET_ACCESS_KEY
AWS_USER_NAME
BUNDLE_WITHOUT
DB_ENDPOINT
DB_NAME
DB_PASSWORD
DB_PORT
DB_USER
DEVISE_SECRET_KEY
DOMAIN
INTERCOM_API_KEY
MANDRILL_SUBACCOUNT
MANDRILL_USERNAME
PARAM5
running diff Ds1 Ps1 returns nothing, i.e. diff considers both files identical AFAIK.
EDIT:
My question is about different outcome of two identical greps and NOT about ways of fast comparison of files.