mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2330 (markdown)
36
SC2330.md
Normal file
36
SC2330.md
Normal file
@@ -0,0 +1,36 @@
|
||||
## BusyBox `[[ .. ]]` does not support glob matching. Use a case statement.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
#!/bin/busybox sh
|
||||
if [[ $1 == https:* ]]
|
||||
then
|
||||
echo "Using URL $1"
|
||||
fi
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
#!/bin/busybox sh
|
||||
case "$1" in
|
||||
https:*)
|
||||
echo "Using URL $1"
|
||||
;;
|
||||
esac
|
||||
```
|
||||
|
||||
### Rationale:
|
||||
|
||||
You are using `[[ .. ]]` in BusyBox `sh` to match against a glob pattern. This is supported in Bash and Ksh, but not in BusyBox.
|
||||
|
||||
Rewrite the match to use a `case` statement instead.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None.
|
||||
|
||||
### Related resources:
|
||||
|
||||
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user