Skip to content

enhancement: standardize shell script quoting and style consistency #33

@doughayden

Description

@doughayden

What

Standardize quoting syntax, variable expansion, and coding style across all shell scripts in the /scripts/ directory to improve maintainability, robustness, and code quality.

Why

  • Robustness: Inconsistent quoting can lead to failures with filenames containing spaces or special characters
  • Maintainability: Consistent style makes code easier to read and modify
  • Best practices: Align with industry-standard shell scripting guidelines
  • Quality: Reduce technical debt and improve overall codebase quality

Scope

The following 8 shell scripts need review and standardization:

  • scripts/bootstrap.sh ⭐ (primary focus - most complex)
  • scripts/install.sh
  • scripts/uninstall.sh
  • scripts/un_bootstrap.sh
  • scripts/set_variables.sh
  • scripts/set_audience.sh
  • scripts/set_token.sh
  • scripts/test_endpoint.sh

Specific Improvements Needed

1. Variable Quoting and Expansion

  • Current issues: Mixed quoting patterns ($var vs "$var" vs "${var}")
  • Target: Consistent use of "${variable}" format throughout
  • Example fixes:
    # Before
    gcloud services enable $service
    grep -q $BUCKET
    
    # After
    gcloud services enable "${service}"
    grep -q "${BUCKET}"

2. Command Substitution

  • Current issues: Mixed quoting in command substitution
  • Target: Consistent double-quote usage
  • Example fix:
    # Before
    user=$(gcloud config list --format='value(core.account)')
    
    # After
    user=$(gcloud config list --format="value(core.account)")

3. Formatting and Style

  • Line length: Break long commands at 80 characters for readability
  • Spacing: Consistent section separation patterns
  • Indentation: Standardize subshell and conditional indentation

4. Error Handling

  • Current: Mix of [ $? -ne 0 ] and [ $? -eq 0 ] patterns
  • Target: Consistent error checking approach
  • Consider: Using set -e for automatic error handling where appropriate

Implementation Guidelines

Reference Standards

  • Google Shell Style Guide
  • Key principles:
    • Always quote variables: "${var}"
    • Use [[ ]] for tests instead of [ ]
    • Maximum 80 character line length
    • 2-space indentation
    • Check return values consistently

Testing Requirements

  • Ensure all scripts maintain current functionality after changes
  • Test with edge cases (spaces in paths, special characters)
  • Validate in both Bash and Zsh environments

Priority and Effort

  • Priority: Low (enhancement/technical debt)
  • Level of Effort: Medium (8 files, systematic changes needed)
  • Timeline: Can be tackled incrementally or as time permits

Additional Considerations

  • Consider adding a shell script linting CI check (shellcheck) after standardization
  • Document any project-specific style decisions in CLAUDE.md
  • This work can be done incrementally, focusing on the most complex scripts first

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions