CLI Tools bash Intermediate

Environment Switcher Script

Switch between named environment profiles stored in ~/.envs/ and export to shell.

bash
#!/bin/bash
# Usage: source envswitch.sh staging
ENV=${1:-development}
FILE=~/.envs/$ENV.env

if [ ! -f "$FILE" ]; then
  echo "Unknown environment: $ENV"
  echo "Available: $(ls ~/.envs/ | sed s/.env//g)"
  return 1
fi

set -a
source "$FILE"
set +a
echo "Loaded $ENV environment"

Prerequisites

  • bash

Pro Tips

  • → Use source (not bash) to export vars to the current shell.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
bash
Level
Intermediate
Read time
2 min
Published
Sep 2026
License
Commercial License

Newsletter

New modules every week, directly to your inbox.