Repository navigation
Description
Bug Description
For ...sh scripts, there is the issue:
Use "[[" instead of "[" for conditional tests
Why is this an issue:
`The traditional [ command (also known as test) is an external command that treats its arguments as separate words, making it vulnerable to word splitting and pathname expansion issues. This can lead to unexpected behavior when variables contain spaces, special characters, or when filenames match glob patterns.
The modern [[ construct is part of Bash syntax rather than a separate command. This means:
Word splitting and pathname expansion do not occur within [[ ]], making it more robust when handling variables that might contain spaces or special characters
It provides better error handling and more predictable behavior
It offers additional features like regular expression matching with the =~ operator
It’s generally faster since it doesn’t require spawning an external process
Using [ can cause subtle bugs that are difficult to debug, especially when dealing with user input, filenames, or variables that might be empty or contain unexpected characters.
What is the potential impact?
Using the traditional [ command instead of [[ can lead to script failures or unexpected behavior when:
Variables contain spaces, tabs, or newlines
Filenames contain special characters or match glob patterns
Variables are empty or unset
These issues can cause scripts to behave unpredictably in production environments, potentially leading to data loss, security vulnerabilities, or system instability. Scripts without a shebang are not checked because their shell interpreter cannot be determined. We assume that POSIX compatibility is required.`
Steps to Reproduce
- specify init my-project --integration
- Chose
shscripts - Open
shscript in.specifyfolder - Validate with SonarQube/Cloud
Expected Behavior
No issue from SonarQube
Actual Behavior
Use "[[" instead of "[" for conditional tests
Specify CLI Version
1.3.2
AI Agent
Claude Code
Operating System
macOS
Python Version
3.11.5
Error Logs
Additional Context
No response
AI Disclosure
N/A
Activity