Not A Member? Who Cares? (Just Click)
Let me set the scene:
It’s 2018.
I’m wearing my socks (a gift from my imaginary girlfriend, who clearly knew what she was signing up for)
The office is empty. The only light comes from my laptop screen, reflecting off a half-eaten bag of stale burger.
I’d just finished refactoring our configuration system — a task that felt like performing open-heart surgery on a hamster. Proud? Absolutely. Until…
I forgot the damn environment variables.
Again.
The .env file sat there, taunting me with its 23 key-value pairs.
Each one needed to be manually exported.
API_KEY.
DATABASE_URL.
AWS_SECRET_ACCESS_KEY.
My fingers hovered over the keyboard. I could already hear my friends at the weekend dinner:
"Where’s Shashwat?"
"Oh, he’s busy typing export for the 47th time."
Until I found a random thread’s comment where there was a cryptic advice:
“Dude, just export $(cat sample.env | xargs)it”
At the time, I’d nodded like I understood.
I did not.
But desperate times call for desperate measures.
And IT WORKEDDDDD GUYS!!!
Breaking Up with Manual Exports: A Love Story
Let’s unpack the wizardry.
1. cat sample.env
This isn’t just "reading a file." This is you, screaming into the void:
"HELLO MACHINE, HERE ARE MY SECRETS. PLEASE DON’T JUDGE MY DEBUG_MODE=true."
2. | xargs
The unsung hero. Imagine xargs as your overworked intern:
"Hey intern, take this list of 23 variables and shove them into a single line. No, I don’t care about the formatting. Just make it work."
3. export $(...)
The $(…) syntax (command substitution) executes the inner command and feeds its output to export.
The finale. You’re basically yelling:
"EVERYTHING IN THIS FILE IS NOW PART OF MY SOUL (or at least this terminal session)."
And yeah, that’s it. It’s indeed just
export $(cat sample.env | xargs)In case we are meeting for the first time, come over here, it’ll be worth the roller coaster of articles that are gonna come up in the next few weeks.
Use this to get to know more about me — https://linktr.ee/shashwat_writes