Skip to content

Instantly share code, notes, and snippets.

@eastlondoner
Last active May 22, 2019 14:34
Show Gist options
  • Save eastlondoner/e136e495822687b37ecb115b249e7f06 to your computer and use it in GitHub Desktop.
Save eastlondoner/e136e495822687b37ecb115b249e7f06 to your computer and use it in GitHub Desktop.
Use whichever python version is available to start a simple http server that serves the current directory.
#!/usr/bin/env bash
set -e
# Example usage: `cd web && PORT=8000 ./serve.sh`
# Default to 8080 if no PORT is specified
PORT="${PORT:-8080}"
# Check which python major version is available and start a simple http server accordingly
if [[ "$(python -c 'import sys; print(sys.version_info[0])')" == "3"* ]]; then
python -m http.server "${PORT}"
else
python -m SimpleHTTPServer "${PORT}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment