mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
Created SC3065 (markdown)
30
SC3065.md
Normal file
30
SC3065.md
Normal file
@@ -0,0 +1,30 @@
|
||||
## In POSIX sh, test -k is undefined.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
if [ -k file ]
|
||||
then
|
||||
echo "File has sticky bit set"
|
||||
fi
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
if [ -n "$(find file -prune -perm /1000)" ]
|
||||
then
|
||||
echo "File has sticky bit set"
|
||||
fi
|
||||
```
|
||||
### Rationale:
|
||||
|
||||
`test -k file` and `[ -k file ]` are not defined by POSIX. To ensure compatibility with all target systems, use `find` instead.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None. If you are targeting a shell that supports `test -k`, specify it in the shebang.
|
||||
|
||||
### Related resources:
|
||||
|
||||
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user