Re: My "Stop Using (and Teaching) C-Shell and Tcsh" Page

"Nadav Har'El" <nyh-TS7m/[email protected]> Sun, 23 Dec 2007 09:48:37 +0200
Newsgroups gmane.culture.hackers.israel
Message-ID <[email protected]>
On Sun, Dec 23, 2007, Beni Cherniavsky wrote about "Re: [hackers-il] My "Stop Using (and Teaching) C-Shell and Tcsh" Page":
> You CAN do anything in sh, but it's defaults are bad, which makes you
> use convoluted syntax or give up and write code with bugs.
> 
> Consider this fish code:
> {{{
> set files (ls)         # splits on \n, creates array
> for f in $files        # space-safe!
>     cp $f ../backup/$f~   # space-safe
> end
> ls -l ../backup/$files~   # space-safe, adds backup/...~ around each word!
> }}}

Just FYI, in ZSH you can do the first 4 lines even more simply, with 2 lines.
Zsh has (by default, when not run in sh compatibility mode) "saner" space-
separation defaults, has syntax shortcuts (no need for do/done when there's
just one line), and can do more things without calling external programs:

	for f in *        # space-safe, and no need to call ls!
	cp $f ../backup/$f~

The 5th line in your example is slightly more complex, and I guess the
bash way you found

> files2=("${files[@]/#/../backup/}")
> ls -l "${files2[@]/%/~}"

Is one way to do it, though in zsh, you don't need to do $files[@], you can do

files=(*)  # space safe
ls -l ${files/#/../backup}

and so on.

> Still, the fact {{{$files}}} only gives the first element of an array,
> so you have to write {{{${files[@]}}}} :-(.

Strange.

> * Minimalistic command expansion syntax: {{{(command)}}}.  LISPers rejoice!

Other ksh-inspired shells (including zsh and bash) already allow the $(...)
syntax. I don't see what removing the extra "$" really buys you.

>   In fish, it's expanded to the pid by the shell, so it's useful in
> any command: {{{pstree %1}}} works!

Interesting. Indeed sounds logical.

> The bottom line is that fish's design is compact and elegant, without
> dirty baggage.

I guess I should take a look at it sometime ;-) Maybe after 15 years with
Zsh (before which I was mostly using ksh), it's time to consider a switch...
Although I'm so pleased with zsh, that Fish would need to be really great
to win me over.

-- 
Nadav Har'El                        |       Sunday, Dec 23 2007, 14 Tevet 5768
nyh-TS7m/[email protected]             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |I have a watch cat! If someone breaks in,
http://nadav.harel.org.il           |she'll watch.