Hi!

* David Garamond; 2003-12-01, 12:43 UTC:
> Josef 'Jupp' SCHUGT wrote:
>> I cannot see anything that requires one-liners besides showing
>> off.  They are not even fun in most cases.
> 
> I find the ability to write one-liners _amazingly_ useful. Perhaps
> you don't use shell/command-line interface much.

If propose one-lines you possibly did not yet discover the *true*
strength of using a CLI. A few years ago I would have supported your
statement. But then I started to use shell multiliners during
interactive sessions.

> But many, many Unix/Linux users do most of their stuffs in shell
> daily. And using a combination of Unix commands sometimes are just
> not powerful/easy/portable enough.  I use Perl & Ruby one-liners
> for all things, from renaming a bunch of files according to some
> string/regex operation (e.g. changing all ".tar.gz" to ".tgz"),

That can easily be done using the following (KSH, Bash should do as
well) three-liner:

for i in *.tar.gz; do
  mv $i ${i%.tar.gz}.tgz
done

One way of achieving the same in Ruby is the following five-liner:

ruby <<EOF
%x(ls *\.tar\.gz).each { |x|
  x.chomp!
  %x(mv #{x} #{x.sub(/\.tar\.gz$/, '.tgz')})
}
EOF

You could also use 'echo' in place of 'ls' but then you would have to
replace 'each' by 'split.each'. Of course You can also do the same in
100% Ruby but I don't see why I should use a scripting language if
the shell allows me to do it more easily so I didn't take the time
for getting rid of ls and mv.

> Btw, I even have a text file where I store hundreds of Perl & Ruby
> one-liners which I can just copy paste to the shell window whenever
> I needs them. It beats having hundreds of script files which I
> don't know how to name properly.

The same works for multiliners as well.

I don't see why to make everything fit into one line if there is no
necessity for it.

Josef 'Jupp' Schugt