why Unix?
grauzone
none at example.net
Tue Apr 7 12:58:34 PDT 2009
Steven Schveighoffer wrote:
> On Tue, 07 Apr 2009 15:03:54 -0400, grauzone <none at example.net> wrote:
>
>> Steven Schveighoffer wrote:
>>> On Tue, 07 Apr 2009 14:35:04 -0400, grauzone <none at example.net> wrote:
>>>
>>>>> But shell scripting in itself is so powerful for this kind of
>>>>> stuff. I've written lots of little scripts to do fantastic things
>>>>> that on Windows would be so painful (without cygwin of course).
>>>>> Like renaming all files of a certain type to something else, or
>>>>> copying select files to another directory.
>>>>
>>>> Now wouldn't that be much more powerful to use an actual programming
>>>> language for this, instead of bash? I claim with something like
>>>> python, bash doesn't really have any right to exist anymore.
>>> I can log into ANY Linux, Solaris, BSD, OSX, etc system and have a
>>> reasonable /bin/sh that allows at least bourne shell functionality.
>>> The same can't be said for almost any other scripting language you
>>> can throw at me.
>>
>> Sure, /bin/sh is the least common denominator. But is there a UNIX
>> that can't run python?
>
> I would guess there isn't. But when someone says, "hey, I need a script
> that does this," I don't ever have to say "oh, you don't have /bin/sh
> installed? Sorry, can't help you."
You have to distinguish between "what would a perfect system look like"
and "how could we improve UNIX". The latter would be replacing sh by
python, I'm well aware that this doesn't work in practice.
>>> Of course, aside from that, I hate python syntax... And can python
>>> be used as a user shell?
>>
>> Don't tell me you hate it more than the clusterfuck that is sh syntax?
>> Reading or writing sh scripts always feels like screwing in bolts into
>> my head.
>
> Yes, I hate it more. sh is a simple syntax (described in 34 pages, most
> of which are builtin functions, of my Unix in a Nutshell book), and has
> no standard library. All the "library" is are standard unix commands.
> I had to fix some shit in the live CD creator script written in python
> on Fedora. It took me a long, long time to figure out what it was
> doing. Does it *really* require you to type self every time you want to
> access a member? And what's up with all the freakin underscores? You
> consider that a good programming syntax? The syntax of python is
> horrendous. The only thing I can think of that's worse is VBScript. It
> might be a good language, but I can't get past the syntax.
The complete language reference (including index) has 102 pages.
Considering that it's probably more formal than the sh description in
your Nutshell book, it's not that much compared to sh.
Regarding the syntax: OK, that's probably about tastes. But I still like
it more than, say, the funny way how you have to use the find program.
>> And regarding using it as an user shell: there's an interactive
>> command line interpreter.
>
> if you type ls, does it work, or do you have to type __run__("ls") or
> whatever?
If you'd go and use python as a shell, you had a ls() function. It would
return an array of names. Instead of text garbage like ls does. How can
you reliably list all files, without getting incorrect results (like
when there's a line break in a file), or falling into the escape trap
(your script, that takes the ls output, interprets part of the filename
as program)?
>>> How would you do the same thing in python? Would it be any clearer
>>> or shorter? Probably not.
>>
>> Not in all cases. But in general, I'd expect it to be clearer. Python
>> is just more similar to normal programming than sh, which is why I'd
>> prefer it.
>
> You thought my script was unclear? I thought you could know exactly
> what it's doing without even knowing sh syntax. Maybe the most
> confusing part was the 'fi' denoting an end of an if statement.
It doesn't really do anything complicated anyway.
> Prove me wrong, show me a python script that does the same thing, and
> we'll see if it's clearer.
Sorry, I'm not going to write a script to prove someone else wrong over
the internet. And my point was anyway to extend a _real_ scripting
language by adding simple functions as substitutes for common UNIX
programs like rm, ln etc.
>>
>> sh scripts aren't very reliable either. I remember that script that
>> invoked another program. That other program produced some warning, and
>> the script interpreted it as normal output.
>
> Oh yeah, that *must* have been the scripting language's fault. I have
> bugs in my D programs too, must be because D sucks?
Interpreting data as programs are the "buffer overflows" of scripting
languages. Nothing to defend here. The script in question was relatively
large, and probably written by some guru, if that helps.
>> And escaping. I don't think there are many scripts that still work
>> correctly if they encounter "strange" filenames, like filenames with
>> spaces, special characters, or even line breaks. Yes, \n is a valid
>> character in UNIX filenames.
>
> That is what single quoting is for. 'xy
> *$123' is that string exactly, no interpretation of any special characters.
>
> Want to know a good trick to play on a unix newbie? Make a file in
> their home directory called *
>
> touch '*'
>
> Not knowing what it is, they try to remove it:
>
> rm *
>
> hilarity ensues :)
Yeah, or doing something like "rm -rf this/directory /". Or deleting all
hidden directories.
That demonstrates a particularly disgusting issue with the shell: escape
hell.
One time, I unzipped a file, and the files were encoded with some weird
multibyte garbage. How do I delete the files? I had to start a GUI
program to do this. In Python, with an appropriate extension library,
that would have been ls() followed by a rm(ls[1]). How to do this in sh?
>>
>>> I'm sure some would argue that there is no point for python if you
>>> can run perl...
>>
>> Perl doesn't have any right to exist either. It has the same brainfuck
>> quirks like sh. For example, defining magical global variables and
>> such. And clusterfuck syntax. It even has a reputation as read-only
>> language.
>>
>> For that matter, any language better than sh or Perl would be better
>> for a shell.
>
> So basically, you don't like other scripting languages so they don't
> have a right to exist? Interesting point of view.
Yes. I usually destroy what I dislike.
> -Steve
More information about the Digitalmars-d
mailing list