Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d037b9f

Browse files
committedMar 24, 2025
fix(SC3013): check POSIX-compliant unary operators for test and [
fix koalaman#2125
1 parent d3001f3 commit d037b9f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎src/ShellCheck/Checks/ShellSupport.hs

+15
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ prop_checkBashisms124 = verify checkBashisms "#!/bin/dash\ntype -p test"
218218
prop_checkBashisms125 = verifyNot checkBashisms "#!/bin/busybox sh\ntype -p test"
219219
prop_checkBashisms126 = verifyNot checkBashisms "#!/bin/busybox sh\nread -p foo -r bar"
220220
prop_checkBashisms127 = verifyNot checkBashisms "#!/bin/busybox sh\necho -ne foo"
221+
prop_checkBashisms128 = verify checkBashisms "#!/bin/sh\n[ -k /tmp ]"
222+
prop_checkBashisms129 = verifyNot checkBashisms "#!/bin/dash\ntest -k /tmp"
223+
prop_checkBashisms130 = verify checkBashisms "#!/bin/sh\n[ -o errexit ]"
221224
checkBashisms = ForShell [Sh, Dash, BusyboxSh] $ \t -> do
222225
params <- ask
223226
kludge params t
@@ -252,6 +255,18 @@ checkBashisms = ForShell [Sh, Dash, BusyboxSh] $ \t -> do
252255
bashism (T_SimpleCommand id _ [asStr -> Just "test", lhs, asStr -> Just op, rhs])
253256
| op `elem` [ "<", ">", "\\<", "\\>", "<=", ">=", "\\<=", "\\>="] =
254257
unless isDash $ warnMsg id 3012 $ "lexicographical " ++ op ++ " is"
258+
bashism (TC_Unary id _ op _)
259+
| op `elem` [ "-k", "-G", "-O" ] =
260+
unless isDash $ warnMsg id 3013 $ op ++ " is"
261+
bashism (T_SimpleCommand id _ [asStr -> Just "test", asStr -> Just op, _])
262+
| op `elem` [ "-k", "-G", "-O" ] =
263+
unless isDash $ warnMsg id 3013 $ op ++ " is"
264+
bashism (TC_Unary id _ op _)
265+
| op `elem` [ "-N", "-o", "-R" ] =
266+
warnMsg id 3013 $ op ++ " is"
267+
bashism (T_SimpleCommand id _ [asStr -> Just "test", asStr -> Just op, _])
268+
| op `elem` [ "-N", "-o", "-R" ] =
269+
warnMsg id 3013 $ op ++ " is"
255270
bashism (TC_Binary id SingleBracket op _ _)
256271
| op `elem` [ "-ot", "-nt", "-ef" ] =
257272
unless isDash $ warnMsg id 3013 $ op ++ " is"

0 commit comments

Comments
 (0)
Please sign in to comment.