← Back to all snippets
BASH

Interactive Project Setup and Configuration

Build an interactive Bash script to guide users through initial project setup, collect configuration details, and generate necessary environment files.

#!/bin/bash

PROJECT_NAME=""
DB_NAME=""
DB_USER=""
DB_PASS=""

echo "--- Project Setup Assistant ---"

read -p "Enter project name (e.g., my-app): " PROJECT_NAME
read -p "Enter database name: " DB_NAME
read -p "Enter database user: " DB_USER
read -s -p "Enter database password: " DB_PASS # -s for silent input
echo "
"

if [ -z "$PROJECT_NAME" ] || [ -z "$DB_NAME" ] || [ -z "$DB_USER" ]; then
  echo "Error: Project name, DB name, and DB user cannot be empty."
  exit 1
fi

# Example: Generate a .env file
ENV_FILE=".env"
cat > "$ENV_FILE" << EOF
APP_NAME=${PROJECT_NAME}
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=${DB_NAME}
DB_USERNAME=${DB_USER}
DB_PASSWORD=${DB_PASS}
EOF

echo "Generated '$ENV_FILE' with your configuration."
echo "Setup complete for project: $PROJECT_NAME"
How it works: This interactive Bash script guides the user through collecting essential project configuration details like project name, database credentials, and other settings. It then uses this input to generate a common `.env` file, automating a critical initial setup task for many web development projects and ensuring consistency.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs