Not sure why Vercel CLI 28.9.0 has no way to import whole .env
file or all environment variables in one project or environment. Write a simple bash script to achieve it:
(Tested on macOS zsh)
Check current environment variables and backup
# List up all current environment variables
vercel env ls
# Backup
vercel env pull .env.production.bak --environment production
vercel env pull .env.development.bak --environment development
vercel env pull .env.preview.bak --environment preview
Add environment variables
cat .env.production | sed 's/=/ /' | xargs -n 2 bash -c 'echo -n $1 | vercel env add $0 production'
cat .env.staging | sed 's/=/ /' | xargs -n 2 bash -c 'echo -n $1 | vercel env add $0 development'
cat .env.staging | sed 's/=/ /' | xargs -n 2 bash -c 'echo -n $1 | vercel env add $0 preview'
Remove all Vercel environment variables
vercel env ls | sed 's/=/ /' | awk 'NR>2 {print $1, $3}' | xargs -n 2 bash -c 'vercel env rm $0 ${1,,} -y'
Top comments (2)
vercel env ls | sed 's/=/ /' | awk 'NR>2 {print $1}' | xargs -n 1 bash -c 'vercel env rm $0 ${1} development
vercel env ls | sed 's/=/ /' | awk 'NR>2 {print $1}' | xargs -n 1 bash -c 'vercel env rm $0 ${1} preview
vercel env ls | sed 's/=/ /' | awk 'NR>2 {print $1}' | xargs -n 1 bash -c 'vercel env rm $0 ${1} production
worked for me
what is windows equivalent of the sam?