mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-13 16:43:20 -07:00
Recognize wait -p as assigning a variable (fixes #2179)
This commit is contained in:
parent
c61fc7546e
commit
da7b28213e
4 changed files with 57 additions and 9 deletions
|
@ -228,6 +228,39 @@ getOpts (gnu, arbitraryLongOpts) string longopts args = process args
|
|||
|
||||
listToArgs = map (\x -> ("", (x, x)))
|
||||
|
||||
|
||||
-- Generic getOpts that doesn't rely on a format string, but may also be inaccurate.
|
||||
-- This provides a best guess interpretation instead of failing when new options are added.
|
||||
--
|
||||
-- "--" is treated as end of arguments
|
||||
-- "--anything[=foo]" is treated as a long option without argument
|
||||
-- "-any" is treated as -a -n -y, with the next arg as an option to -y unless it starts with -
|
||||
-- anything else is an argument
|
||||
getGenericOpts :: [Token] -> [(String, (Token, Token))]
|
||||
getGenericOpts = process
|
||||
where
|
||||
process (token:rest) =
|
||||
case getLiteralStringDef "\0" token of
|
||||
"--" -> map (\c -> ("", (c,c))) rest
|
||||
'-':'-':word -> (takeWhile (`notElem` "\0=") word, (token, token)) : process rest
|
||||
'-':optString ->
|
||||
let opts = takeWhile (/= '\0') optString
|
||||
in
|
||||
case rest of
|
||||
next:_ | "-" `isPrefixOf` getLiteralStringDef "\0" next ->
|
||||
map (\c -> ([c], (token, token))) opts ++ process rest
|
||||
next:remainder ->
|
||||
case reverse opts of
|
||||
last:initial ->
|
||||
map (\c -> ([c], (token, token))) (reverse initial)
|
||||
++ [([last], (token, next))]
|
||||
++ process remainder
|
||||
[] -> process remainder
|
||||
[] -> map (\c -> ([c], (token, token))) opts
|
||||
_ -> ("", (token, token)) : process rest
|
||||
process [] = []
|
||||
|
||||
|
||||
-- Is this an expansion of multiple items of an array?
|
||||
isArrayExpansion (T_DollarBraced _ _ l) =
|
||||
let string = concat $ oversimplify l in
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue