Berkeley CSUA MOTD:Entry 25243
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2002/6/29-30 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:25243 Activity:high
6/28    I have been repeatedly warned *not* to write shell scripts in
        csh/tcsh.  Is there any validity to these warnings? If so, why?
        \_ Warned by?  I write all my personal stuff in whatever the fuck I
           want (csh/tcsh/perl).  I write anything for init.d in /bin/sh
           because /bin/sh should always work so the scripts are 100%
           guaranteed portable. (heh).  /bin/sh pretty much sucks and has
           near-zero useful features but it's there.
        \_ Instead of posting your question to the motd try putting it
           to google. http://www.faqs.org/faqs/unix-faq/shell/csh-whynot
           is the classic article that explains why it's not a great idea.
           \_ For starters let's note this was written in 1996.  A lot of the
              bugs he's picking on aren't out there anymore.  A lot of the
              examples he's using are a bit contrived.  I agree csh is not the
              best thing to write in if you're going to stick it in /etc/init.d
              or write a large script that does something important but for a
              quick hack, why not?  It's there, you know it, use it and throw
              it out.  Anything longer than 5 or 10 lines is probably a Perl
              job anyway.  /bin/sh for /etc/init.d, tcsh for fun, Perl for
              real work.  Just one man's world view.
              \_ When are you people going to move to Ruby?  Perl sucks.
                 \_ When Ruby has something that looks like CPAN so I don't
                    have to reinvent the wheel everytime I want to do something
                    interesting.  I started Perl at 4.015.  Lemme know when
                    Ruby is as useful as Perl was 5+ years ago.
                    \_ CPAN ugh. That is the worst thing to happen to perl
                       with the possible exception of the stupid OO crap.
                       Perl 4 was the last great perl, it had everything that
                       was missing from Perl 3 without any of the messy
                       non-sense of Perl 5 (about the only thing that Perl 5
                       add that is of any value is my).
                       \_ CPAN is bad uh how?  And Perl5 added real structures
                          to the language making it much more useful.  If all
                          you wanted was sed/awk, use sed/awk.  Some of us are
                          too busy to reinvent the wheel or fucking around with
                          the broken data structures in Perl4.
              \_ It was written in the 80s
                 \_ Even more so then.  The date inside the URL said 96.
                    \_ It's just as relevant now.  csh still can't do basic
                       stuff like redirect STDOUT and STDERR to different
                       places.  It's a fine login shell, but it sucks for
                       programming.  -tom
                       \_ Uhm, on that point in particular, you're wrong:
                          (command >stdoutgoeshere) >&stderrgoeshere
                          (admittedly, it can't, say, juxtapose the two, but
                          that's not needed too often)             -alexf
                       \_ Why would anyone want to use (t)csh in a world
                          where ksh and bash exist?
                   Who uses ksh? _/
                          \_ Because bash is broken and stupid?
                       \_ uh... % ( some-command > someplace ) >& other-place
                      \_ I've never wanted to do the obscure shit he's talking
                         about csh not supporting.  That's what perl is for
                         anyway.  /bin/sh and perl covers everything.
                         \_ if /bin/sh and perl covers everything, why are
                            you programming in csh?
                            And really, it's pathetic that csh can't handle
                            trivial, obvious syntax like:
                            "if ( "$foo" == "bar" )".  You run into shit like
                            that all the time with csh.  -tom
                                 \- writing stuff in csh to me is like using
                                    vi for quick edits ... no matter how quick
                                    or trivial you think it will be, about
                                    half the time you get started doing
                                    something more involved and regret not
                                    starting out doing it right ... however
                                    if you want an objective list of drawbacks
                                    and gotchas in csh, that is a decent list.
                                    when it comes to tcsh there are some bugs,
                                    but everything has bugs ... those things
                                    in the famous doc are mostly design flaws.
                                    if csh works you you, do what you want.
                                    a very imporant piece of "code" at lbl
                                    consists of 3024 lines of csh ... it was
                                    supposed to be a 20 line program.
                                    "bill joy has a lot to answer for"
                                    --psb
ERROR, url_link recursive (eces.Colorado.EDU/secure/mindterm2) 2025/05/24 [General] UID:1000 Activity:popular
5/24    

You may also be interested in these entries...
2008/3/4-7 [Computer/Networking, Computer/SW/Languages/Perl] UID:49324 Activity:moderate
3/4     Does anybody have some code or know of a program that will take a
        network/mask and return the list of address in that CIDR block?
        e.g. "iplist 10.10.10.0/24" and return 10.10.10.0 ... 10.10.10.255
        [I have a way to do this, but it involves distributing a large
        amount of code, which is kind of a hassle. Looking for something
        lightweight and either standard or easdy to rpm/port/yum install.]
	...
2007/9/10 [Computer/SW/Languages/Perl] UID:47986 Activity:low
9/10    Hi.  I'm running a package based linux distro.  Should
        I install perl CPAN modules through the provided packages,
        or through sudo cpan> install modulename etc ?
        Opinions?
        \_ Depends on the package system you're using, you may have to
           deal with both.  I had an experience where I installed via
	...
2007/8/7-13 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:47555 Activity:nil
8/7     I'm trying to figure out whether it's possible for get wget to
        authenticate to a web page protected by a login form ('post'
        method to send username/pass, and cookies.)  Cookies don't seem
        to be the problem, with --save-cookies and --keep-session-cookies
        but getting the username/password submitted isn't doing it.  On
        this particular page, getting to a link, let's say 'example.aspx',
	...
2006/6/29-7/3 [Computer/SW/Languages/Perl] UID:43527 Activity:nil
6/29    Visual Programming in Perl:
        http://search.cpan.org/dist/Acme-EyeDrops/lib/Acme/EyeDrops.pm
	...
2005/9/2-3 [Computer/SW/Languages/Perl] UID:39466 Activity:nil
9/2     Hey motd I used to have perl w/DBI 1.42 & DBD 2.9003. After
        upgrading Perl, DBI 1.48, & DBD 3.0002_1 I'm seeing something
        really weird. The following used to work:
        $dbh=$DBI->prepare("INSERT INTO data VALUES(\?)");
        for ($i=0; $i<10; $i++) {
          if (!$dbh->execute($i)) {
	...
2005/8/31 [Computer/SW/Languages/Perl] UID:39376 Activity:nil
8/31    Looking for an XML parser for Perl, preferably one that
        doesn't require installation (something already built in).
        If it's not already built in, I prefer something that doesn't
        require C compilation, and that I can just stick the *.pm
        to use. I'm looking for portability, not performance. Thanks.
        \_ What's wrong with using CPAN?
	...
2004/4/10-12 [Computer/SW/Languages/Perl] UID:13128 Activity:nil
4/10    In perl, how do I get time precise to the milisecond? The CPAN module
        requires recompilation and root access to install it, I'm looking for
        something more portable. Thanks!
        \_ If you need to know the time, there's no portable way to do it
           without modules.  However, if you just want a sub-second delay,
           you can do it with select -- for example, select "", "", "", 0.1;
	...
2004/4/12 [Computer/SW/Languages/Perl] UID:13154 Activity:nil
4/12    What's a good perl module (cpan) that strips off all the html
        tags and javascript crap? And perhaps be smart enough to strip
        off menus and ads? Thanks.
        \_ lynx -dump <pagename>
        \_ s/<[^>]*>//g
	...
2004/3/29-30 [Computer/SW/OS/FreeBSD, Computer/SW/OS/OsX] UID:12920 Activity:high
3/29    I'm installing binaries for both OsX and Linux and I'd like all the
        users to have /usr/bin/<files> to be accessible. I thought about
        /usr/bin/<files> for generic stuff (like scripts) and
        /usr/bin/<platform>/<files> for platform specific things.
        What is the correct approach to this?
        \_ there are obviously several ways to do this, and "correct" is mostly
	...
2004/3/30 [Computer/SW/OS/FreeBSD, Computer/SW/OS/OsX] UID:29888 Activity:high
3/29      I'm installing binaries for both OsX and Linux and I'd like all the
          users to have /usr/bin/<files> to be accessible. I thought about
          /usr/bin/<files> for generic stuff (like scripts) and
          /usr/bin/<platform>/<files> for platform specific things.
          What is the correct approach to this?
        \_ there are obviously several ways to do this, and "correct" is mostly
	...
2003/8/29-2004/2/14 [Computer/SW/Languages/Perl, Computer/SW/Unix] UID:12252 Activity:nil
2/13    Does perl have a "diff" facility? I have something that requires a
        lot of diff but file I/O using unix diff would be too slow. Thanks.
        \_ Text::Diff?  Really.  You could search cpan for this sort of thing.
	...
2003/9/9 [Computer/SW/Languages/Perl] UID:10121 Activity:high
9/8     Any recommendations for a text-based Yahoo instant messanger app
        for linux that logs.
        \_ Yahoo::Messenger
           \_ what do you mean, there isn't a CPAN module by that name.
              \_ Sorry, Net::YahooMessenger, but really, you could have
                 tried searching.
	...
2012/8/29-11/7 [Computer/SW/Security] UID:54467 Activity:nil
8/29    There was once a CSUA web page which runs an SSH client for logging
        on to soda.  Does that page still exist?  Can someone remind me of the
        URL please?  Thx.
        \_ what do you mean? instruction on how to ssh into soda?
           \_ No I think he means the ssh applet, which, iirc, was an applet
              that implemented an ssh v1 client.  I think this page went away
	...
2012/9/20-11/7 [Computer/SW/Unix, Finance/Investment] UID:54482 Activity:nil
9/20    How do I change my shell? chsh says "Cannot change ID to root."
        \_ /usr/bin/chsh does not have the SUID permission set. Without
           being set, it does not successfully change a user's shell.
           Typical newbie sys admin (on soda)
           \_ Actually, it does: -rwsr-xr-x 1 root root 37552 Feb 15  2011 /usr/bin/chsh
	...
2012/9/24-11/7 [Computer/SW/Languages, Computer/SW/Unix] UID:54484 Activity:nil
9/24    How come changing my shell using ldapmodify (chsh doesn't work) doesn't
        work either? ldapsearch and getent show the new shell but I still get
        the old shell on login.
        \_ Scratch that, it magically took my new shell now. WTF?
           \_ probably nscd(8)
	...
2012/3/29-6/4 [Computer/HW/Memory, Computer/HW/CPU, Computer/HW/Drives] UID:54351 Activity:nil
3/29    A friend wants a PC (no mac). She doesn't want Dell. Is there a
        good place that can custom build for you (SSD, large RAM, cheap video
        card--no game)?
        \_ As a side note: back in my Cal days more than two decades ago when
           having a 387SX made me the only person with floating-point hardware,
           most machines were custom built.
	...
2012/4/27-6/4 [Computer/SW/Languages/Misc, Computer/SW/Unix] UID:54372 Activity:nil
4/27    I wrote a little shell script to collect iostat data:
        #!/bin/bash
        DATE=`date +%m%d`
        DATADIR=/var/tmp/user
        OUTPUTFILE=$DATADIR/$DATE.out
        while true
	...
2012/1/27-3/26 [Computer/SW/Unix] UID:54299 Activity:nil
1/27    Interesting list of useful unix tools. Shout out to
        cowsay even!
        http://www.stumbleupon.com/su/3428AB/kkovacs.eu/cool-but-obscure-unix-tools
        \_ This is nice.  Thanks.
	...
2011/10/26-12/6 [Computer/SW/Unix] UID:54202 Activity:nil
10/24  What's an easy way to see if say column 3 of a file matches a list of
       expressions in a file? Basically I want to combine "grep -f <file>"
       to store the patterns and awk's $3 ~ /(AAA|BBB|CCC)/ ... I realize
       I can do this with "egrep -f " and use regexp instead of strings, but
       was wondering if there was some magic way to do this.
       \_ UNIX has no magic. Make a shell script to produce the ask or egrep
	...
2011/5/19-7/30 [Computer/SW/Security] UID:54110 Activity:nil
5/19    Uh, is anyone still using this? Please mark here if you post and
        haven't added this yet. I'll start:
        \_ person k
        \_ ausman, I check in about once a week.
        \_ erikred, twice a week or so.
        \_ mehlhaff, I login when I actually own my home directory instead of
	...
2011/5/19-7/13 [Computer/SW/Languages/Misc] UID:54115 Activity:nil
5/19    If script A runs, and calls script B ..... is it possible for me to exit\
        script A based on results of script B and not continue?
        \_ assume any shell
        \_ Yes.
           \_ without passing the result to some stupid temp file?
              \_ It sounds like you want "scriptb || exit", which will run
	...
Cache (8165 bytes)
www.faqs.org/faqs/unix-faq/shell/csh-whynot -> www.faqs.org/faqs/unix-faq/shell/csh-whynot/
I am continually shocked and dismayed to see people write test cases, install scripts, and other random hackery using the csh. The csh is seductive because the conditionals are more C-like, so the path of least resistance is chosen and a csh script is written. Sadly, this is a lost cause, and the programmer seldom even realizes it, even when they find that many simple things they wish to do range from cumbersome to impossible in the csh. FILE DESCRIPTORS The most common problem encountered in csh programming is that you can't do file-descriptor manipulation. All you are able to do is redirect stdin, or stdout, or dup stderr into stdout. Bourne-compatible shells offer you an abundance of more exotic possibilities. Writing Files In the Bourne shell, you can open or dup arbitrary file descriptors. Or what if you just want to throw away stderr and leave stdout alone? In the csh, you can only make a pitiful attempt like this: (cmd > /dev/tty) >& /dev/null But who said that stdout was my tty? Along these same lines, you can't direct error messages in csh scripts out stderr as is considered proper. In the Bourne shell, you might say: echo "$0: cannot find $file" 1>&2 but in the csh, you can't redirect stdout out stderr, so you end up doing something silly like this: sh -c 'echo "$0: cannot find $file" 1>&2' 1b. Reading Files In the csh, all you've got is $<, which reads a line from your tty. Tough noogies, you still get your tty, which you really can't redirect. Now, the read statement in the Bourne shell allows you to read from stdin, which catches redirection. It also means that you can do things like this: exec 3<file1 exec 4<file2 Now you can read from fd 3 and get lines from file1, or from file2 through fd 4. In modern, Bourne-like shells, this suffices: read some_var 0<&3 read another_var 0<&4 Although in older ones where read only goes from 0, you trick it: exec 5<&0 # save old stdin exec 0<&3; Closing FDs In the Bourne shell, you can close file descriptors you don't want open, like 2>&-, which isn't the same as redirecting it to /dev/null. More Elaborate Combinations Maybe you want to pipe stderr to a command and leave stdout alone. In a Bourne shell, you can do things like this: exec 3>&1; The closes there were in case something really cared about all its FDs. But if you want it from A, you're out of luck -- if you're in the csh, that is. In the Bourne shell, you can get it, although doing so is a bit tricky. Here's something I had to do where I ran dd's stderr into a grep -v pipe to get rid of the records in/out noise, but had to return the dd's exit status, not the grep's: device=/dev/rmt8 dd_noise='^ 0-9 +\+ 0-9 + records (in|out)$' exec 3>&1 status=((dd if=$device ibs=64k 2>&1 1>&3 3>&- 4>&-; Even simple little things like this: % time | echo which while nonsensical, shouldn't give me this message: Reset tty pgrp from 9341 to 26678 Others are more fun: % sleep 1 | while while: Too few arguments. White space can matter: if(expr) may fail on some versions of csh, while if (expr) works! Your vendor may have attempted to fix this bug, but odds are good that their csh still won't be able to handle if then if then echo A: got here else echo B: got here endif echo We should never execute this statement endif 3. SIGNALS In the csh, all you can do with signals is trap SIGINT. In the Bourne shell, you can trap any signal, or the end-of-program exit. For example, to blow away a tempfile on any of a variety of signals: $ trap 'rm -f /usr/adm/tmp/i$$ ; This makes it really hard to construct strings with mixed quotes in them. You have to use backslashes for newlines, and it's just darn hard to get them into strings sometimes. VARIABLE SYNTAX There's this big difference between global (environment) and local (shell) variables. In csh, you use a totally different syntax to set one from the other. In the Bourne shell, this VAR=foo cmds args is the same as (export VAR; Watch: echo Try testing with $SHELL:t It's really nice to be able to say ${PAGER-more} or FOO=${BAR:-${BAZ}} to be able to run the user's PAGER if set, and more otherwise. You can't get the process number of the last background command from the csh, something you might like to do if you're starting up several jobs in the background. The csh is also flaky about what it does when it imports an environment variable into a local shell variable, as it does with HOME, USER, PATH, and TERM. Consider this: % setenv TERM '/bin/ls -l / > /dev/tty' % csh -f And watch the fun! MANPAGER) setenv PAGER $MANPAGER Despite your attempts to only set PAGER when you want to, the csh aborts: MANPAGER: Undefined variable. That's because it parses the whole line anyway AND EVALUATES IT! X && $X == 'foo') echo ok X: Undefined variable This forces you to write a couple nested if statements. This is highly undesirable because it renders short-circuit booleans useless in situations like these. If the csh were the really C-like, you would expect to be able to safely employ this kind of logic. Consider the common C construct: if (p && p->member) Undefined variables are not fatal errors in the Bourne shell, so this issue does not arise there. While the csh does have built-in expression handling, it's not what you might think. This is an error @ a = 4/2 but this is ok @ a = 4 / 2 The ad hoc parsing csh employs fouls you up in other places as well. ERROR HANDLING Wouldn't it be nice to know you had an error in your script before you ran it? This is especially good to make sure seldom taken segments of code code are correct. Consider this statement: exit Of course, they really meant exit or just exit 1 Either shell will complain about this. If you have an alias with backquotes, and use that in backquotes in another one, you get a coredump. Here's another one: % mkdir tst % cd tst % touch ' foo bar' % foreach var ( * ) > echo "File named $var" > end foreach: No match. SUMMARY While some vendors have fixed some of the csh's bugs (the tcsh also does much better here), many have added new ones. Most of its problems can never be solved because they're not actually bugs per se, but rather the direct consequences of braindead design decisions. Do yourself a favor, and if you *have* to write a shell script, do it in the Bourne shell. The Korn shell is the preferred programming shell by many sh addicts, but it still suffers from inherent problems in the Bourne shell's design, such as parsing and evaluation horrors. The Korn shell or its public-domain clones and supersets (like bash) aren't quite so ubiquitous as sh, so it probably wouldn't be wise to write a sharchive in them that you post to the net. Until then, we'll be stuck with bug-incompatible versions of the sh lying about. The Plan 9 shell, rc, is much cleaner in its parsing and evaluation; If you don't have to use a shell, but just want an interpreted language, many other free possibilities present themselves, like Perl, REXX, TCL, Scheme, or Python. Of these, Perl is probably the most widely available on UNIX (and many other) systems and certainly comes with the most extensive UNIX interface. Increasing numbers vendors ship Perl with their standard systems. You can get at networking functions, binary data, and most of the C library. There are also translators to turn your sed and awk scripts into Perl scripts, as well as a symbolic debugger. Tchrist's personal rule of thumb is that if it's the size that fits in a Makefile, it gets written in the Bourne shell, but anything bigger gets written in Perl. He calls it 'csh' or the 'hamilton csh', but it's not a csh as it's neither bug nor feature compatible with the real csh. Actually, he's fixed a great deal, but in doing so, has created a totally different shell. Vote 16 Current Top-Rated FAQs Are you an expert in this area? Share your knowledge and earn expert points by giving answers or rating people's questions and answers! ORG is not sanctioned in any way by FAQ authors or maintainers. Questions strongly related to this FAQ: * 17 i want to get some exmaples of shell programming i mean the problems by Puneet (2/14/2004) * 18 hi all, i need to write a csh script in which i run a perl script.