Merge pull request #1499 from jabberabbe/iss896-printf-v-arrays
Fix issues #896 and #433: printf -v and arrays
This commit is contained in:
commit
05e657e130
|
@ -1954,6 +1954,7 @@ prop_checkUnassignedReferences33= verifyNotTree checkUnassignedReferences "f() {
|
||||||
prop_checkUnassignedReferences34= verifyNotTree checkUnassignedReferences "declare -A foo; (( foo[bar] ))"
|
prop_checkUnassignedReferences34= verifyNotTree checkUnassignedReferences "declare -A foo; (( foo[bar] ))"
|
||||||
prop_checkUnassignedReferences35= verifyNotTree checkUnassignedReferences "echo ${arr[foo-bar]:?fail}"
|
prop_checkUnassignedReferences35= verifyNotTree checkUnassignedReferences "echo ${arr[foo-bar]:?fail}"
|
||||||
prop_checkUnassignedReferences36= verifyNotTree checkUnassignedReferences "read -a foo -r <<<\"foo bar\"; echo \"$foo\""
|
prop_checkUnassignedReferences36= verifyNotTree checkUnassignedReferences "read -a foo -r <<<\"foo bar\"; echo \"$foo\""
|
||||||
|
prop_checkUnassignedReferences37= verifyNotTree checkUnassignedReferences "var=howdy; printf -v 'array[0]' %s \"$var\"; printf %s \"${array[0]}\";"
|
||||||
checkUnassignedReferences params t = warnings
|
checkUnassignedReferences params t = warnings
|
||||||
where
|
where
|
||||||
(readMap, writeMap) = execState (mapM tally $ variableFlow params) (Map.empty, Map.empty)
|
(readMap, writeMap) = execState (mapM tally $ variableFlow params) (Map.empty, Map.empty)
|
||||||
|
|
|
@ -649,7 +649,11 @@ getModifiedVariableCommand base@(T_SimpleCommand _ _ (T_NormalWord _ (T_Literal
|
||||||
|
|
||||||
getPrintfVariable list = f $ map (\x -> (x, getLiteralString x)) list
|
getPrintfVariable list = f $ map (\x -> (x, getLiteralString x)) list
|
||||||
where
|
where
|
||||||
f ((_, Just "-v") : (t, Just var) : _) = return (base, t, var, DataString $ SourceFrom list)
|
f ((_, Just "-v") : (t, Just var) : _) = return (base, t, varName, varType $ SourceFrom list)
|
||||||
|
where
|
||||||
|
(varName, varType) = case elemIndex '[' var of
|
||||||
|
Just i -> (take i var, DataArray)
|
||||||
|
Nothing -> (var, DataString)
|
||||||
f (_:rest) = f rest
|
f (_:rest) = f rest
|
||||||
f [] = fail "not found"
|
f [] = fail "not found"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue