News for hackers. Stuff that matters.
Re:Zsh is your friend. by jff on Tuesday January 31, 2012 @01:12PM (#3534409)
Try Plan 9's "rc". It has a more C-like syntax, so you write things like "for (i in `{seq 1 100}) { echo $i }"; I really enjoy writing in rc.
Re:Zsh is your friend. by drothlis on Wednesday February 01, 2012 @05:10AM (#3537381)
One of my favourite aspects of rc is the sane array handling.

In bash: $array expands to the _first_ element of the array; you have to say ${array[@]} to get the whole array. And then you have to quote it in case one of the elements has spaces.

In rc: $array expands to the whole array, and the expansion is _not_ re-parsed, so if an element of the array has spaces in it, it is still considered a single element after the array variable expansion.

For this reason rc doesn't even need double-quoting; it only has single-quoting for escaping spaces in string literals.

Re:Zsh is your friend. by naner on Tuesday January 31, 2012 @01:17PM (#3534431)
How is that better than

bash or zsh:

    for i in `seq 1 100`; do echo $i; done
zsh:

    for i in `seq 1 100`; echo $i
Re:Zsh is your friend. by chalst on Wednesday February 01, 2012 @06:01AM (#3537465)
The rc example is worse than the first of yours. I hate the zsh special syntax in the second: it violates a deeply ingrained code feel I have about the syntax of shell code. The do ... done syntax helps the eye.

rc really shines when you have problems that in bash or zsh would suggest using multiple layers of expansion. The semantics of rc's expansion is much less thorny.

I prefer real examples - here, why not just write

    seq 1 100
- what is the loop for? And shell loops can frequently (always, if you are willing to write helper scripts) be replaced with xargs, which tends to be very much faster, e.g.

    seq 1 100 |  xargs echo
(which doesn't quite give the same output, but passing -n1 to xargs fixes that)
Re:Zsh is your friend. by nimrody on Tuesday January 31, 2012 @01:41PM (#3534575)
It's sort of ok when its `do... done`. But what about `if`..`fi` or `case`..`esac`.

+1 for rc.

Re:Zsh is your friend. by wonderzombie on Tuesday January 31, 2012 @03:00PM (#3534914)
Honestly, I find that stuff pretty easy to remember. And is it that ugly, in the grand scheme of ugly shell syntax? :)

I mean, what about [[ ]] vs. (( )) vs. [ ]? Or the beginning of a case statement? Those always get me since I don't use them often enough for them to stick.

Re:Zsh is your friend. by pyre on Tuesday January 31, 2012 @03:22PM (#3534995)
[ ] is easy. It's just the 'test' command.[1]

  % which \[
  /usr/bin/[
All of the other syntax is shell-specific (run via built-ins), so that can vary, and be a little more obtuse.

[1] Albiet with some minor differences:

  % if [ -d /tmp ]; then echo "TRUE"; fi
  TRUE
  
  % if test -d /tmp ]; then echo "TRUE"; fi
  test: too many arguments
  
  % if test -d /tmp; then echo "TRUE"; fi 
  TRUE

  % diff /usr/bin/{test,\[}
  Binary files /usr/bin/test and /usr/bin/[ differ

  % man \[
  No manual entry for [
Re:Zsh is your friend. by ori_b on Tuesday January 31, 2012 @08:58PM (#3536270)
Yes. rc has less of it, fewer edge cases, etc. Even though it still has lists implemented sanely, a full set of redirects, etc:

    $ 9 man rc | wc -l
    496
    $ man bash | wc -l
    4890
Fewer interactive features as well, unfortunately. But it's small enough to keep in your head, and I find that makes it far more pleasant to use.
Re:Zsh is your friend. by rcfox on Tuesday January 31, 2012 @03:14PM (#3534968)
Even better: for i in {1..100}; echo $i