I'm stumped here: I have a bash script which reads a series of variables out of a .env
file, and then runs a few commands using those values. But the behavior is completely confusing to me. Here's a simplified example:
The contents of my .env file are:
GCS_BUCKET_NAME="my-bucket"
GCS_ROOT_FOLDER="my-folder"
And the script is:
if [ -f .env ]; then
#load the .env file
echo "Loading environment..."
source .env &>/dev/null
echo ""
echo "GCS Bucket: $GCS_BUCKET_NAME"
echo "GCS Root Folder: $GCS_ROOT_FOLDER"
echo ""
PATH_TO_FOLDER=gs://${GCS_BUCKET_NAME}/${GCS_ROOT_FOLDER}
echo $PATH_TO_FOLDER
else
echo "No .env file found."
fi
The output of running this script is:
Loading environment...
GCS Bucket: my-bucket
GCS Root Folder: my-folder
/my-foldercket
...How am I winding up with /my-foldercket
?
If I instead define the variables inline:
#!/bin/bash
GCS_BUCKET_NAME="my-bucket"
GCS_ROOT_FOLDER="my-folder"
echo ""
echo "GCS Bucket: $GCS_BUCKET_NAME"
echo "GCS Root Folder: $GCS_ROOT_FOLDER"
echo ""
PATH_TO_FOLDER=gs://${GCS_BUCKET_NAME}/${GCS_ROOT_FOLDER}
echo $PATH_TO_FOLDER
I get this output:
GCS Bucket: my-bucket
GCS Root Folder: my-folder
gs://my-bucket/my-folder
...which is what I'd expect.
What on earth is going on here?