Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Bourne / bash problem



2009/4/26 Nguyen Vu Hung <vuhung16plus@example.com>:

> The OP limited himself doing brain surgery with a hammer,

Maybe, and maybe not. If you want to tie a bunch of tools together in
a pipeline but want to save yourself some typing (or shell history
searching), a shell script is much more suited for the job than Perl
or Python.

> With scripting languages like Perl or Python, we can have
> same effect and readable code.

For certain classes of problems, sure. For the standard UNIX idiom of
piping 13 commands together, I'd argue that a shell script is much
more readable.

> IMO, most of the options
> are self explained, right? Or they should be. So the comments like that
> won't be necessary, at least for me as I can read and write English :D

Are you kidding me? Have you read many man pages for standard binutils
recently? How about shell built-ins? How about GNU utilities that
don't even have man pages but rather some brain-dead thing called
info?

Do you remember what this does?

cp -dipRux foo bar

or would you like a comment?

When writing shell scripts, you (by definition) have no control over
the options the programs you are calling require. If you use Perl,
sure, you can build the command one crazy option at a time, and do
something "readable" like this:

my %cp_option_for = ;
my $cp_src = 'foo';
my $cp_dst = 'bar';
my $cmd = 'cp -'
    . values(%{
        no_dereference_preserve_links             => 'd',
        interactive                                           => 'i',
        preserve_mode_ownership_timestamps => 'p',
        recursive                                             => 'R',
        update                                                => 'u',
        one_file_system                                  => 'x',
    })
    . " $cp_src $cp_dst"
    ;
unless (0 == system $cmd) {
    ...
}

-- 
Cheers,
Josh


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links