6 ms·
Is it that hard to remember a bash for loop? for i in $(seq 1 10) do echo $i done Then you can just replace new lines with ; if writing a one liner.
by macromagnon 5y ago
Is it that hard to remember a bash for loop?
for i in $(seq 1 10)
do echo $i
done
Then you can just replace new lines with ; if writing a one liner.
for i in $(seq 1 10); do echo $i; done
I guess it isn't as simple as python
for i in range(10): print(i)
but it's pretty close aside from the variable binding.
- yesenadam 5y agofor i in {1..10}
- alerighi 5y agoIn zsh you can avoid the do if you have a single instruction: for i in {1..10}; echo $i to me is as clear as the python version. Very compact and useful for one liners.
- shakna 5y agoBash has some subtleties around loops that can be frustrating, like the body of your loop _may_ actually be running in a subshell (common when iterating over a file), making it difficult to extract what you want from it.
- bandie91 5y agoi bet it's the `cat file | while read …` loop what you are referring to, not any loop. but correct me.
- ulam2 5y agoAs someone dealing with new remote machines on a daily basis, I cannot fantasize about any other shell. Bash is pretty straightforward.
- tekknik 5y agoAnd look at all of those finger bending symbols!