Skip to content

Instantly share code, notes, and snippets.

@dreygur
Created October 23, 2023 17:31
Show Gist options
  • Select an option

  • Save dreygur/ae9a9745a3244cae0a82ed2e1ae8485a to your computer and use it in GitHub Desktop.

Select an option

Save dreygur/ae9a9745a3244cae0a82ed2e1ae8485a to your computer and use it in GitHub Desktop.
#!/bin/bash
envs_folder="envs"
bot_file="bot.js"
for env_file in "$envs_folder"/*.env; do
filename=$(basename "$env_file")
echo "Setting environment variables from file: $filename"
while IFS= read -r line; do
if [[ "$line" == *=* ]]; then
key="${line%%=*}"
value="${line#*=}"
export "$key=$value"
fi
done < "$env_file"
echo "Running javascript file with Node in a new terminal window..."
gnome-terminal -- bash -c "node $bot_file; exec bash"
# Clear the environment variables after each iteration
while IFS= read -r line; do
if [[ "$line" == *=* ]]; then
key="${line%%=*}"
unset "$key"
fi
done < "$env_file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment