zlacker

[parent] [thread] 7 comments
1. wpm+(OP)[view] [source] 2026-01-07 18:37:53
Is

for i in 1..10 {

    print $i
}

really all that more readable than

for i in {1..10}; do

    print $i
done

Like, am I taking crazy pills? They're basically exactly the same!

replies(4): >>kalter+j7 >>cassep+Mc >>Qwerti+Tv >>runjak+Yy
2. kalter+j7[view] [source] 2026-01-07 19:09:26
>>wpm+(OP)
Bash is an advanced beast. In Bourne, it was

    for i in `seq 10`
    do
        print $i
    done
Which is pretty much readable though. The only issue is Pascal vs C syntax. As a fan of the former, I admit that the latter is more advanced: it stacks better. E.g. consider

    if (test -f junk) rm junk
against

    if test -f junk; then rm junk; fi
The former “avoids semicolons that Bourne requires in odd places, and the syntax characters better set off the active parts of the command.” [1]

1: Rc—The Plan 9 Shell https://9p.io/sys/doc/rc.html

replies(1): >>wpm+1F
3. cassep+Mc[view] [source] 2026-01-07 19:34:50
>>wpm+(OP)
I have never seen the second version. Apparently it's there since bash 3.00 (2004). Maybe took inspiration from zsh who also has (or a common ancestor ?)
4. Qwerti+Tv[view] [source] 2026-01-07 20:53:53
>>wpm+(OP)
The former is easier to remember. You can't forget the semicolon if there isn't a semicolon to forget.
5. runjak+Yy[view] [source] 2026-01-07 21:03:22
>>wpm+(OP)
It depends on where you're coming from.

To myself, I agree, but to a Windows native power user, the latter looks confusing.

Source: Windows native colleagues.

replies(1): >>wpm+PF
◧◩
6. wpm+1F[view] [source] [discussion] 2026-01-07 21:25:52
>>kalter+j7
The semicolon is required only when not using new lines to split the command words, as in

sleep 60; do_the_thing_that_needs_a_minute_wait

It's not necessarily required in the for loop either, I tend to prefer the more compact method of putting the "do" on the same line as the for. It can be written as

for i in {1..10}

do

    print $1
done

Having "done" be the signifier of the "the for loop context ends here" is 3 characters more than "}" or ")" or whatever else. "done" is more color coming off the screen with syntax-highlighting, and can be typed in two keypresses with a "d" and a "tab" in any editor from the last 30 years. It just seems like a very very inconsequential nitpick. At least Nushell doesn't pull a Python and just have "invisible space" be the end of the for-loop.

One line conditionals are doable as well in the shell.

test -f junk && junk

or

[[ -f junk ]] && junk

You can even just use [ -f junk ] if double brackets is giving the yuck.

replies(1): >>kalter+lc1
◧◩
7. wpm+PF[view] [source] [discussion] 2026-01-07 21:28:11
>>runjak+Yy
Imagine though, if we shell-heads came over to Windows and started writing an entirely new shell to replace Powershell because we didn't want to learn Powershell. It's just so utterly bizarre to me. I guess people like what they like, and that's cool, but wanting to rip out a 40+ year old scripting environment and command line shell because it doesn't look like goddamn Ruby or Clojure or Rust or whatever is just intolerable.
◧◩◪
8. kalter+lc1[view] [source] [discussion] 2026-01-08 00:07:43
>>wpm+1F
In practice, the only noticeable difference I have witnessed is

    for (f in *.c) if (test -f $f) cc $f
I can write the whole thing in a single line (which is essential in GUI and interactive contexts) and it reads well.
[go to top]