1

I currently have multiple branded apps. Each app has a dotenv file where several configurations are being manipulated. Example config: .env.Branded_App

PROJECT_PATH = SOME_PROJECT_PATH
ASSET_PATH = SOME_ASSET_PATH

My goal is to use a shell script to automate running each command. For example I want a shell script file to accomplish something like:

comannd 1
command 2
etc

When I run "command 1" individually in my terminal everything is running as expected. Branded_App environment variables are pulled in from the desired config file. Project & asset paths would be passed normally to desired locations.

When I start the shell file with the same command, the shell isn't recognizing the environment variables being passed in. Terminal will ask me for project and asset paths. I believe this is because the shell file is creating a separate shell session when being run?

"fastlane build --env Branded_App" --> This works with the correct environment customizations for "Branded_App" individually in terminal
"fastlane build --env Branded_App" --> Does not run the exact same or pull in environment variables when calling with the shell script

How can I make sure the shell script command produces the same result as running each command individually?

Derek
  • 11
  • 2
  • 1
  • @Dennis It looks like my bash terminal recognizes the .env.Branded_App file, but it isn't pulling any values from there. Instead, it acts like the file is blank. I tried the export method above but unfortunately it did not seem to resolve the issue. – Derek May 25 '21 at 20:33
  • Hi @Derek - In that case, I don't see enough information to be able to help you out. If you were to post the script (trimmed down to the bare essentials) showing the problem, and better examples than "command 1" "command 2" et cetera, we have a chance to move forward. – Dennis May 26 '21 at 02:47
  • This will demonstrate what I'm talking about. Create a shell script file (let's say, /tmp/echovars) as follows: **echo 'echo $A; echo $B; echo $C' > /tmp/echovars** Be sure to set executable permissions (**chmod +x /tmp/echovars**). Then in your terminal, type **A="1"; B="2"; C=3; /tmp/echovars ** (don't type the asterisks) ---Note that echovars prints three blank lines. Now type **export A C; /tmp/echovars ** (don't type the asterisks) Note that echovars now prints your EXPORTED variables. They MUST be exported in order to be seen by any children of your shell process. – Dennis May 26 '21 at 03:08
  • Update - I have my .env configs partially working now. The solution I found was to add: `export $(grep -v '^#' .env.BrandedApp | xargs -0)` to the shell file. This reads over the target .env config and exports the values. This also will skip over lines with the "#" value. The only issue I am facing now is that it does not export values with spaces in them. For reference I am going off of Nate & Silas answer in this thread: https://stackoverflow.com/questions/19331497/set-environment-variables-from-file-of-key-value-pairs/30969768#30969768 – Derek May 30 '21 at 17:24

0 Answers0