We make very careful considerations about the interface and operation of the GNU coreutils, but unfortunately due to backwards compatibility reasons, some behaviours or defaults of these utilities can be confusing.
This information will continue to be updated and overlaps somewhat with the coreutils FAQ, with this list focusing on less frequent potential issues.
Good tips and reminders for those who don't work mostly with a CLI (Command Line Interface).
[What has been YOUR biggest CLI gotcha? -Ed.]
(Score: 2, Informative) by xav on Wednesday December 02 2015, @03:55AM
My favorite gotcha is the difference between the for loop and the while loop in bash. While loops create subshells with a new environment while for loops do not.
No, pipes do create subshells, not "while".
What I mean is that
# seq 1 3 | while read n; do echo $n; done
creates two subshells for seq and while, whereas
# for n in $(seq 1 3); do echo $n; done
creates only one subshell for seq, not for the "for" loop.
On the other hand, the two following while loops do the same thing in the current shell:
# while read n; do echo $n; done <<< "$(seq 1 3)"
# while read n; do echo $n; done < <(seq 1 3)