Shell script best practices
Follow these shell script best practices when writing or modifying bash scripts:1. Use `#!/usr/bin/env bash` instead of `#!/bin/bash` for better portabilityBad:```bash#!/bin/bashecho "Hello World"```Install this rule for wispbit Cloud
Add this rule to wispbit and it will run when you open a pull request
Install this rule with wispbit CLI
Run this command in your terminal to install the rule locally
Install this rule for Coderabbit
Copy the configuration below and add it to your repository as .coderabbit.yml in your project root.
reviews: path_instructions: - path: "*.sh" instructions: | Follow these shell script best practices when writing or modifying bash scripts: 1. Use `#!/usr/bin/env bash` instead of `#!/bin/bash` for better portability Bad: ```bash #!/bin/bash echo "Hello World" ``` Good: ```bash #!/usr/bin/env bash echo "Hello World" ``` 2. Use `${variable}` syntax for all variable references Bad: ```bash name="Alice" echo "Hello $name" ``` Good: ```bash name="Alice" echo "Hello ${name}" ``` 3. Use double quotes around variable expansions to prevent word splitting and globbing Bad: ```bash files=$(ls) for file in $files; do rm $file done ``` Good: ```bash files=$(ls) for file in "${files}"; do rm "${file}" done ``` 4. Use `[[` and `]]` instead of `[` and `]` for conditional expressions Bad: ```bash if [ -z "$input" ] || [ "$input" = "exit" ]; then echo "Exiting..." exit 0 fi ``` Good: ```bash if [[ -z "${input}" || "${input}" = "exit" ]]; then echo "Exiting..." exit 0 fi ``` 5. Use `printf '%s\n'` instead of `echo` for output with special characters Bad: ```bash output="Text with special chars: * & $HOME" echo $output ``` Good: ```bash output="Text with special chars: * & $HOME" printf '%s\n' "${output}" ``` 6. Use `readonly` for constants that should not be modified Bad: ```bash CONFIG_PATH="/etc/app/config.json" LOG_DIR="/var/log/app" ``` Good: ```bash readonly CONFIG_PATH="/etc/app/config.json" readonly LOG_DIR="/var/log/app" ``` 7. Use `|` as delimiter in `sed` commands when replacing paths containing slashes Bad: ```bash sed -i "s/${source_path}/${target_path}/" "${config_file}" ``` Good: ```bash sed -i "s|${source_path}|${target_path}|" "${config_file}" ``` Install this rule for Greptile
Greptile rules can be added through the web interface. Please see this documentation for details on how to add custom rules and context.
Follow these shell script best practices when writing or modifying bash scripts:1. Use `#!/usr/bin/env bash` instead of `#!/bin/bash` for better portabilityBad:```bash#!/bin/bashecho "Hello World"```Good:```bash#!/usr/bin/env bashecho "Hello World"```2. Use `${variable}` syntax for all variable referencesBad:```bashname="Alice"echo "Hello $name"```Good:```bashname="Alice"echo "Hello ${name}"```3. Use double quotes around variable expansions to prevent word splitting and globbingBad:```bashfiles=$(ls)for file in $files; do rm $filedone```Good:```bashfiles=$(ls)for file in "${files}"; do rm "${file}"done```4. Use `[[` and `]]` instead of `[` and `]` for conditional expressionsBad:```bashif [ -z "$input" ] || [ "$input" = "exit" ]; then echo "Exiting..." exit 0fi```Good:```bashif [[ -z "${input}" || "${input}" = "exit" ]]; then echo "Exiting..." exit 0fi```5. Use `printf '%s\n'` instead of `echo` for output with special charactersBad:```bashoutput="Text with special chars: * & $HOME"echo $output```Good:```bashoutput="Text with special chars: * & $HOME"printf '%s\n' "${output}"```6. Use `readonly` for constants that should not be modifiedBad:```bashCONFIG_PATH="/etc/app/config.json"LOG_DIR="/var/log/app"```Good:```bashreadonly CONFIG_PATH="/etc/app/config.json"readonly LOG_DIR="/var/log/app"```7. Use `|` as delimiter in `sed` commands when replacing paths containing slashesBad:```bashsed -i "s/${source_path}/${target_path}/" "${config_file}"```Good:```bashsed -i "s|${source_path}|${target_path}|" "${config_file}"```File Path Patterns:
Install this rule for GitHub Copilot
Copilot instructions can be added through the interface. See the documentation for details on how to create coding guidelines.
Follow these shell script best practices when writing or modifying bash scripts:1. Use `#!/usr/bin/env bash` instead of `#!/bin/bash` for better portabilityBad:```bash#!/bin/bashecho "Hello World"```Good:```bash#!/usr/bin/env bashecho "Hello World"```2. Use `${variable}` syntax for all variable referencesBad:```bashname="Alice"echo "Hello $name"```Good:```bashname="Alice"echo "Hello ${name}"```3. Use double quotes around variable expansions to prevent word splitting and globbingBad:```bashfiles=$(ls)for file in $files; do rm $filedone```Good:```bashfiles=$(ls)for file in "${files}"; do rm "${file}"done```4. Use `[[` and `]]` instead of `[` and `]` for conditional expressionsBad:```bashif [ -z "$input" ] || [ "$input" = "exit" ]; then echo "Exiting..." exit 0fi```Good:```bashif [[ -z "${input}" || "${input}" = "exit" ]]; then echo "Exiting..." exit 0fi```5. Use `printf '%s\n'` instead of `echo` for output with special charactersBad:```bashoutput="Text with special chars: * & $HOME"echo $output```Good:```bashoutput="Text with special chars: * & $HOME"printf '%s\n' "${output}"```6. Use `readonly` for constants that should not be modifiedBad:```bashCONFIG_PATH="/etc/app/config.json"LOG_DIR="/var/log/app"```Good:```bashreadonly CONFIG_PATH="/etc/app/config.json"readonly LOG_DIR="/var/log/app"```7. Use `|` as delimiter in `sed` commands when replacing paths containing slashesBad:```bashsed -i "s/${source_path}/${target_path}/" "${config_file}"```Good:```bashsed -i "s|${source_path}|${target_path}|" "${config_file}"```File Path Patterns:
Install this rule for Graphite Diamond
Diamond custom rules can be added through the interface. See the documentation for details on how to create custom rules.
Follow these shell script best practices when writing or modifying bash scripts:1. Use `#!/usr/bin/env bash` instead of `#!/bin/bash` for better portabilityBad:```bash#!/bin/bashecho "Hello World"```Good:```bash#!/usr/bin/env bashecho "Hello World"```2. Use `${variable}` syntax for all variable referencesBad:```bashname="Alice"echo "Hello $name"```Good:```bashname="Alice"echo "Hello ${name}"```3. Use double quotes around variable expansions to prevent word splitting and globbingBad:```bashfiles=$(ls)for file in $files; do rm $filedone```Good:```bashfiles=$(ls)for file in "${files}"; do rm "${file}"done```4. Use `[[` and `]]` instead of `[` and `]` for conditional expressionsBad:```bashif [ -z "$input" ] || [ "$input" = "exit" ]; then echo "Exiting..." exit 0fi```Good:```bashif [[ -z "${input}" || "${input}" = "exit" ]]; then echo "Exiting..." exit 0fi```5. Use `printf '%s\n'` instead of `echo` for output with special charactersBad:```bashoutput="Text with special chars: * & $HOME"echo $output```Good:```bashoutput="Text with special chars: * & $HOME"printf '%s\n' "${output}"```6. Use `readonly` for constants that should not be modifiedBad:```bashCONFIG_PATH="/etc/app/config.json"LOG_DIR="/var/log/app"```Good:```bashreadonly CONFIG_PATH="/etc/app/config.json"readonly LOG_DIR="/var/log/app"```7. Use `|` as delimiter in `sed` commands when replacing paths containing slashesBad:```bashsed -i "s/${source_path}/${target_path}/" "${config_file}"```Good:```bashsed -i "s|${source_path}|${target_path}|" "${config_file}"```File Path Patterns:
Use with Cline
Copy the rule below and ask Cline to review your code using this rule
Follow these shell script best practices when writing or modifying bash scripts:1. Use `#!/usr/bin/env bash` instead of `#!/bin/bash` for better portabilityBad:```bash#!/bin/bashecho "Hello World"```Good:```bash#!/usr/bin/env bashecho "Hello World"```2. Use `${variable}` syntax for all variable referencesBad:```bashname="Alice"echo "Hello $name"```Good:```bashname="Alice"echo "Hello ${name}"```3. Use double quotes around variable expansions to prevent word splitting and globbingBad:```bashfiles=$(ls)for file in $files; do rm $filedone```Good:```bashfiles=$(ls)for file in "${files}"; do rm "${file}"done```4. Use `[[` and `]]` instead of `[` and `]` for conditional expressionsBad:```bashif [ -z "$input" ] || [ "$input" = "exit" ]; then echo "Exiting..." exit 0fi```Good:```bashif [[ -z "${input}" || "${input}" = "exit" ]]; then echo "Exiting..." exit 0fi```5. Use `printf '%s\n'` instead of `echo` for output with special charactersBad:```bashoutput="Text with special chars: * & $HOME"echo $output```Good:```bashoutput="Text with special chars: * & $HOME"printf '%s\n' "${output}"```6. Use `readonly` for constants that should not be modifiedBad:```bashCONFIG_PATH="/etc/app/config.json"LOG_DIR="/var/log/app"```Good:```bashreadonly CONFIG_PATH="/etc/app/config.json"readonly LOG_DIR="/var/log/app"```7. Use `|` as delimiter in `sed` commands when replacing paths containing slashesBad:```bashsed -i "s/${source_path}/${target_path}/" "${config_file}"```Good:```bashsed -i "s|${source_path}|${target_path}|" "${config_file}"```Use with OpenAI Codex
Copy the rule below and ask OpenAI Codex to review your code using this rule
Follow these shell script best practices when writing or modifying bash scripts:1. Use `#!/usr/bin/env bash` instead of `#!/bin/bash` for better portabilityBad:```bash#!/bin/bashecho "Hello World"```Good:```bash#!/usr/bin/env bashecho "Hello World"```2. Use `${variable}` syntax for all variable referencesBad:```bashname="Alice"echo "Hello $name"```Good:```bashname="Alice"echo "Hello ${name}"```3. Use double quotes around variable expansions to prevent word splitting and globbingBad:```bashfiles=$(ls)for file in $files; do rm $filedone```Good:```bashfiles=$(ls)for file in "${files}"; do rm "${file}"done```4. Use `[[` and `]]` instead of `[` and `]` for conditional expressionsBad:```bashif [ -z "$input" ] || [ "$input" = "exit" ]; then echo "Exiting..." exit 0fi```Good:```bashif [[ -z "${input}" || "${input}" = "exit" ]]; then echo "Exiting..." exit 0fi```5. Use `printf '%s\n'` instead of `echo` for output with special charactersBad:```bashoutput="Text with special chars: * & $HOME"echo $output```Good:```bashoutput="Text with special chars: * & $HOME"printf '%s\n' "${output}"```6. Use `readonly` for constants that should not be modifiedBad:```bashCONFIG_PATH="/etc/app/config.json"LOG_DIR="/var/log/app"```Good:```bashreadonly CONFIG_PATH="/etc/app/config.json"readonly LOG_DIR="/var/log/app"```7. Use `|` as delimiter in `sed` commands when replacing paths containing slashesBad:```bashsed -i "s/${source_path}/${target_path}/" "${config_file}"```Good:```bashsed -i "s|${source_path}|${target_path}|" "${config_file}"```Use with Cursor
Copy the rule below and ask Cursor to review your code using this rule
Follow these shell script best practices when writing or modifying bash scripts:1. Use `#!/usr/bin/env bash` instead of `#!/bin/bash` for better portabilityBad:```bash#!/bin/bashecho "Hello World"```Good:```bash#!/usr/bin/env bashecho "Hello World"```2. Use `${variable}` syntax for all variable referencesBad:```bashname="Alice"echo "Hello $name"```Good:```bashname="Alice"echo "Hello ${name}"```3. Use double quotes around variable expansions to prevent word splitting and globbingBad:```bashfiles=$(ls)for file in $files; do rm $filedone```Good:```bashfiles=$(ls)for file in "${files}"; do rm "${file}"done```4. Use `[[` and `]]` instead of `[` and `]` for conditional expressionsBad:```bashif [ -z "$input" ] || [ "$input" = "exit" ]; then echo "Exiting..." exit 0fi```Good:```bashif [[ -z "${input}" || "${input}" = "exit" ]]; then echo "Exiting..." exit 0fi```5. Use `printf '%s\n'` instead of `echo` for output with special charactersBad:```bashoutput="Text with special chars: * & $HOME"echo $output```Good:```bashoutput="Text with special chars: * & $HOME"printf '%s\n' "${output}"```6. Use `readonly` for constants that should not be modifiedBad:```bashCONFIG_PATH="/etc/app/config.json"LOG_DIR="/var/log/app"```Good:```bashreadonly CONFIG_PATH="/etc/app/config.json"readonly LOG_DIR="/var/log/app"```7. Use `|` as delimiter in `sed` commands when replacing paths containing slashesBad:```bashsed -i "s/${source_path}/${target_path}/" "${config_file}"```Good:```bashsed -i "s|${source_path}|${target_path}|" "${config_file}"```Use with Claude Code
Copy the rule below and ask Claude Code to review your code using this rule
Follow these shell script best practices when writing or modifying bash scripts:1. Use `#!/usr/bin/env bash` instead of `#!/bin/bash` for better portabilityBad:```bash#!/bin/bashecho "Hello World"```Good:```bash#!/usr/bin/env bashecho "Hello World"```2. Use `${variable}` syntax for all variable referencesBad:```bashname="Alice"echo "Hello $name"```Good:```bashname="Alice"echo "Hello ${name}"```3. Use double quotes around variable expansions to prevent word splitting and globbingBad:```bashfiles=$(ls)for file in $files; do rm $filedone```Good:```bashfiles=$(ls)for file in "${files}"; do rm "${file}"done```4. Use `[[` and `]]` instead of `[` and `]` for conditional expressionsBad:```bashif [ -z "$input" ] || [ "$input" = "exit" ]; then echo "Exiting..." exit 0fi```Good:```bashif [[ -z "${input}" || "${input}" = "exit" ]]; then echo "Exiting..." exit 0fi```5. Use `printf '%s\n'` instead of `echo` for output with special charactersBad:```bashoutput="Text with special chars: * & $HOME"echo $output```Good:```bashoutput="Text with special chars: * & $HOME"printf '%s\n' "${output}"```6. Use `readonly` for constants that should not be modifiedBad:```bashCONFIG_PATH="/etc/app/config.json"LOG_DIR="/var/log/app"```Good:```bashreadonly CONFIG_PATH="/etc/app/config.json"readonly LOG_DIR="/var/log/app"```7. Use `|` as delimiter in `sed` commands when replacing paths containing slashesBad:```bashsed -i "s/${source_path}/${target_path}/" "${config_file}"```Good:```bashsed -i "s|${source_path}|${target_path}|" "${config_file}"```Install this rule for Windsurf
To set up rules for Windsurf Reviews, please see this documentation
Follow these shell script best practices when writing or modifying bash scripts:1. Use `#!/usr/bin/env bash` instead of `#!/bin/bash` for better portabilityBad:```bash#!/bin/bashecho "Hello World"```Good:```bash#!/usr/bin/env bashecho "Hello World"```2. Use `${variable}` syntax for all variable referencesBad:```bashname="Alice"echo "Hello $name"```Good:```bashname="Alice"echo "Hello ${name}"```3. Use double quotes around variable expansions to prevent word splitting and globbingBad:```bashfiles=$(ls)for file in $files; do rm $filedone```Good:```bashfiles=$(ls)for file in "${files}"; do rm "${file}"done```4. Use `[[` and `]]` instead of `[` and `]` for conditional expressionsBad:```bashif [ -z "$input" ] || [ "$input" = "exit" ]; then echo "Exiting..." exit 0fi```Good:```bashif [[ -z "${input}" || "${input}" = "exit" ]]; then echo "Exiting..." exit 0fi```5. Use `printf '%s\n'` instead of `echo` for output with special charactersBad:```bashoutput="Text with special chars: * & $HOME"echo $output```Good:```bashoutput="Text with special chars: * & $HOME"printf '%s\n' "${output}"```6. Use `readonly` for constants that should not be modifiedBad:```bashCONFIG_PATH="/etc/app/config.json"LOG_DIR="/var/log/app"```Good:```bashreadonly CONFIG_PATH="/etc/app/config.json"readonly LOG_DIR="/var/log/app"```7. Use `|` as delimiter in `sed` commands when replacing paths containing slashesBad:```bashsed -i "s/${source_path}/${target_path}/" "${config_file}"```Good:```bashsed -i "s|${source_path}|${target_path}|" "${config_file}"```