Skip to content

Commit efffc61

Browse files
committed
Warn about string operations on $@/$* (fixes #1236)
1 parent 135cf59 commit efffc61

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/ShellCheck/Checks/ShellSupport.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ prop_checkBashisms51= verifyNot checkBashisms "#!/bin/sh\ncmd 2>&1"
134134
prop_checkBashisms52= verifyNot checkBashisms "#!/bin/sh\ncmd >&2"
135135
prop_checkBashisms53= verifyNot checkBashisms "#!/bin/sh\nprintf -- -f\n"
136136
prop_checkBashisms54= verify checkBashisms "#!/bin/sh\nfoo+=bar"
137+
prop_checkBashisms55= verify checkBashisms "#!/bin/sh\necho ${@%foo}"
138+
prop_checkBashisms56= verifyNot checkBashisms "#!/bin/sh\necho ${##}"
137139
checkBashisms = ForShell [Sh, Dash] $ \t -> do
138140
params <- ask
139141
kludge params t
@@ -295,8 +297,9 @@ checkBashisms = ForShell [Sh, Dash] $ \t -> do
295297
(re $ "^[" ++ varChars ++ "]+\\[.*\\]$", "array references are"),
296298
(re $ "^![" ++ varChars ++ "]+\\[[*@]]$", "array key expansion is"),
297299
(re $ "^![" ++ varChars ++ "]+[*@]$", "name matching prefixes are"),
298-
(re $ "^[" ++ varChars ++ "]+:[^-=?+]", "string indexing is"),
299-
(re $ "^[" ++ varChars ++ "]+(\\[.*\\])?/", "string replacement is")
300+
(re $ "^[" ++ varChars ++ "*@]+:[^-=?+]", "string indexing is"),
301+
(re $ "^([*@][%#]|#[@*])", "string operations on $@/$* are"),
302+
(re $ "^[" ++ varChars ++ "*@]+(\\[.*\\])?/", "string replacement is")
300303
]
301304
bashVars = [
302305
"LINENO", "OSTYPE", "MACHTYPE", "HOSTTYPE", "HOSTNAME",

0 commit comments

Comments
 (0)