-
Notifications
You must be signed in to change notification settings - Fork 1.9k
SC2043
This loop will only ever run once for a constant value. Did you perhaps mean to loop over dir/*, $var or $(cmd)?
for var in value
do
echo "$var"
doneCorrect code depends on what you want to do.
To iterate over files in a directory, instead of for var in /my/dir use:
for var in /my/dir/* ; do echo "$var"; doneTo iterate over lines in a file or command output, use a while read loop instead:
mycommand | while IFS= read -r line; do echo "$line"; doneTo iterate over words written to a command or function's stdout, instead of for var in myfunction, use
for var in $(myfunction); do echo "$var"; doneTo iterate over words in a variable, instead of for var in myvariable, use
for var in $myvariable; do echo "$var"; doneShellCheck has detected that your for loop iterates over a single, constant value. This is most likely a bug in your code, caused by you not expanding the value in the way you want.
You should make sure that whatever you loop over will expand into multiple words.
If you stylistically choose to use for loops with a single element, e.g. to align with other code or to set up for future extensibility (for target in x86_64; do ..), you can ignore this warning.