From mboxrd@z Thu Jan 1 00:00:00 1970 Mime-Version: 1.0 (Apple Message framework v753) In-Reply-To: <599f06db0802100859l2a13a8e7o9d6a492138d44421@mail.gmail.com> References: <599f06db0802100859l2a13a8e7o9d6a492138d44421@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Message-Id: <41F23396-1019-4C8E-A65A-E42824B0E23B@mac.com> Content-Transfer-Encoding: quoted-printable From: Pietro Gagliardi Subject: Re: [9fans] How to move to rc from sh/bash Date: Sun, 10 Feb 2008 12:16:50 -0500 To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Topicbox-Message-UUID: 4ec324e8-ead3-11e9-9d60-3106f5b1d025 On Feb 10, 2008, at 11:59 AM, Gorka Guardiola wrote: > On Feb 9, 2008 8:53 AM, Hongzheng Wang wrote: >> Hi all, >> >> 2. In non-interactive use (script programming), what's the main >> advantages of rc over sh/bash? > > Things I like of rc: > > In both interactive and non-interactive, spaces do not bite you in rc. > > in bash > > if [ $bla -eq $otherbla ] ; fi endif... ahhh, I can=B4t remember the > syntax and get the spaces wrong, The proper is if [ $bla -eq $otherbla ]; then : fi The advantage of rc is that that : is not necessary! Oh, and let's not forget what happens when bla or otherbla is nil! In =20= rc, if (~ $bla $otherbla) { } is all that is needed - no hooks. > > Someone else said it, only one quoting simbol > (what does " bla \$e'o" do on bash?, I just invented it, but every =20 > time I see > double qoutes I start trembling) It produces the string ' bla$e''o' in rc syntax. The one thing I like =20= about two quoting styles in the Bourne shell is that I can use =20 escape sequences. The one thing I dislike about bash is that bash =20 fucks up this quote system. > And here is my 2 cents: - List objects are STANDARD (bash/kornshell arrays are not) x=3D(a b c) - The seq statement is standard for (i in `{seq 1 10}) echo $i - Removable functions fn x { echo 4 } fn x x=3D4 - >[] piping syntax is much more intuitive - |[2] to pipe arbitrary file descriptors. One time, to skim through =20 errors from gcc to find out if I had mistyped a member of a struct, I =20= had to do gcc a_file_in_my_os.c 2>&1 | grep member In rc: 8c a_file_in_my_os.c |[2] grep member - Empty condition bodies! while(){echo y} is the yes command. It's =20 much more terse. - aux/getflags is faster than while getopt (no loop involved) My next plan is to rewrite all of /rc/bin to use aux/getflags. = Any =20 objections? - The trap statement is gone - goodbye confusing hooks and no way of =20 telling signal 1 from a command/function called 1 Instead, you define functions sigterm and sigkill (I think) And what I dislike: - >[2=3D] is not the same as >[2]/dev/null (some programs crash with =20 the former