1
0
mirror of https://github.com/koalaman/shellcheck.git synced 2025-03-12 12:35:25 -07:00

Added check for A=foo | grep bar

This commit is contained in:
Vidar Holen 2012-11-27 00:41:10 -08:00
parent 0ca6d0f6cc
commit a8715d2d5f

@ -64,6 +64,7 @@ basicChecks = [
,checkEcho
,checkConstantIfs
,checkTrAZ
,checkPipedAssignment
]
modifyMap = modify
@ -135,6 +136,15 @@ checkEcho (T_Pipeline id [a, b]) =
checkEcho _ = return ()
checkEchoSedRe = mkRegex "^s(.)(.*)\\1(.*)\\1g?$"
prop_checkPipedAssignment1 = verify checkPipedAssignment "A=ls | grep foo"
prop_checkPipedAssignment2 = verifyNot checkPipedAssignment "A=foo cmd | grep foo"
prop_checkPipedAssignment3 = verifyNot checkPipedAssignment "A=foo"
checkPipedAssignment (T_Pipeline _ (T_Redirecting _ _ (T_SimpleCommand id (_:_) []):_:_)) =
warn id "If you wanted to assign the output of the pipeline, use a=$(b | c)"
checkPipedAssignment _ = return ()
prop_checkUuoc = verify checkUuoc "cat foo | grep bar"
checkUuoc (T_Pipeline _ (T_Redirecting _ _ f@(T_SimpleCommand id _ _):_:_)) =
case deadSimple f of ["cat", _] -> style id "Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead."