Skip to main content
added 35 characters in body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Your loop uses krn as the loop variable. This is also the name of the array that you loop over. The shell does not maintain separate name spaces for array variables and non-array variables.

For each iteration, krn will be set to the current value from the array. This has the effect of modifying the array's first element in every iteration. The loop modifies the array so that the first element will be a copy of the last element after the end of the loop.

To correct this, choose another name for the loop variable, or for the array.


Additionally, you should use "${krn[@]}" (the expansion, double quoted) in the loop head as using ${krn[@]} unquoted would split each element on whitespaces (or whatever is in $IFS) and invoke filename globbing on the resulting words. The same goes for echo "${krn[i]}" in the later loop.

TheAssuming there is at least one element in the array, the whole loop could alternatively be replaced by

((${#krn[@]})) && printf '%s\n' "${krn[@]}" 

Your loop uses krn as the loop variable. This is also the name of the array that you loop over. The shell does not maintain separate name spaces for array variables and non-array variables.

For each iteration, krn will be set to the current value from the array. This has the effect of modifying the array's first element in every iteration. The loop modifies the array so that the first element will be a copy of the last element after the end of the loop.

To correct this, choose another name for the loop variable, or for the array.


Additionally, you should use "${krn[@]}" (the expansion, double quoted) in the loop head as using ${krn[@]} unquoted would split each element on whitespaces (or whatever is in $IFS) and invoke filename globbing on the resulting words. The same goes for echo "${krn[i]}" in the later loop.

The whole loop could alternatively be replaced by

((${#krn[@]})) && printf '%s\n' "${krn[@]}" 

Your loop uses krn as the loop variable. This is also the name of the array that you loop over. The shell does not maintain separate name spaces for array variables and non-array variables.

For each iteration, krn will be set to the current value from the array. This has the effect of modifying the array's first element in every iteration. The loop modifies the array so that the first element will be a copy of the last element after the end of the loop.

To correct this, choose another name for the loop variable, or for the array.


Additionally, you should use "${krn[@]}" (the expansion, double quoted) in the loop head as using ${krn[@]} unquoted would split each element on whitespaces (or whatever is in $IFS) and invoke filename globbing on the resulting words. The same goes for echo "${krn[i]}" in the later loop.

Assuming there is at least one element in the array, the whole loop could alternatively be replaced by

printf '%s\n' "${krn[@]}" 
The case where the array is empty must be treated specially for it to be equivalent to the loop
Source Link
Stéphane Chazelas
  • 586.2k
  • 96
  • 1.1k
  • 1.7k

Your loop uses krn as the loop variable. This is also the name of the array that you loop over. The shell does not maintain separate name spaces for array variables and non-array variables.

For each iteration, krn will be set to the current value from the array. This has the effect of modifying the array's first element in every iteration. The loop modifies the array so that the first element will be a copy of the last element after the end of the loop.

To correct this, choose another name for the loop variable, or for the array.


Additionally, you should use "${krn[@]}" (the expansion, double quoted) in the loop head as using ${krn[@]} unquoted would split each element on whitespaces (or whatever is in $IFS) and invoke filename globbing on the resulting words. The same goes for echo "${krn[i]}" in the later loop.

The whole loop could alternatively be replaced by

((${#krn[@]})) && printf '%s\n' "${krn[@]}" 

Your loop uses krn as the loop variable. This is also the name of the array that you loop over. The shell does not maintain separate name spaces for array variables and non-array variables.

For each iteration, krn will be set to the current value from the array. This has the effect of modifying the array's first element in every iteration. The loop modifies the array so that the first element will be a copy of the last element after the end of the loop.

To correct this, choose another name for the loop variable, or for the array.


Additionally, you should use "${krn[@]}" (the expansion, double quoted) in the loop head as using ${krn[@]} unquoted would split each element on whitespaces (or whatever is in $IFS) and invoke filename globbing on the resulting words. The same goes for echo "${krn[i]}" in the later loop.

The whole loop could alternatively be replaced by

printf '%s\n' "${krn[@]}" 

Your loop uses krn as the loop variable. This is also the name of the array that you loop over. The shell does not maintain separate name spaces for array variables and non-array variables.

For each iteration, krn will be set to the current value from the array. This has the effect of modifying the array's first element in every iteration. The loop modifies the array so that the first element will be a copy of the last element after the end of the loop.

To correct this, choose another name for the loop variable, or for the array.


Additionally, you should use "${krn[@]}" (the expansion, double quoted) in the loop head as using ${krn[@]} unquoted would split each element on whitespaces (or whatever is in $IFS) and invoke filename globbing on the resulting words. The same goes for echo "${krn[i]}" in the later loop.

The whole loop could alternatively be replaced by

((${#krn[@]})) && printf '%s\n' "${krn[@]}" 
edited body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

Your loop uses krn as the loop variable. This is also the name of the array that you loop over. The shell does not maintain separate name spaces for array variables and non-array variables.

For each iteration, krn will be set to the current value from the array. This has the effect of modifying the array's first element in every iteration. The loop modifies the array so that the first element will be a copy of the last element after the end of the loop.

To correct this, choose another name for the loop variable, or for the array.


Additionally, you should use "${krn[@]}" (the expansion, double quoted) in the loop head as using ${krn[@]} unquoted would split each element on whitespaces (or whatever is in $IFS) and invoke filename globbing on the resulting words. The same goes for echo "${krn[i]}" in the later loop.

The whole loop could alternatively be replaced by

printf '%s\n' "${krn[@]}" 

Your loop uses krn as the loop variable. This is also the name of the array that you loop over. The shell does not maintain separate name spaces for array variables and non-array variables.

For each iteration, krn will be set to the current value from the array. This has the effect of modifying the array's first element in every iteration. The loop modifies the array so that the first element will be a copy of the last element after the end of the loop.

To correct this, choose another name for the loop variable, or for the array.


Additionally, you should use "${krn[@]}" (the expansion, double quoted) in the loop head as using ${krn[@]} unquoted would split each element on whitespaces (or whatever is in $IFS) and invoke filename globbing on the resulting words.

Your loop uses krn as the loop variable. This is also the name of the array that you loop over. The shell does not maintain separate name spaces for array variables and non-array variables.

For each iteration, krn will be set to the current value from the array. This has the effect of modifying the array's first element in every iteration. The loop modifies the array so that the first element will be a copy of the last element after the end of the loop.

To correct this, choose another name for the loop variable, or for the array.


Additionally, you should use "${krn[@]}" (the expansion, double quoted) in the loop head as using ${krn[@]} unquoted would split each element on whitespaces (or whatever is in $IFS) and invoke filename globbing on the resulting words. The same goes for echo "${krn[i]}" in the later loop.

The whole loop could alternatively be replaced by

printf '%s\n' "${krn[@]}" 
edited body
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
Loading
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k
Loading