News for hackers. Stuff that matters.
Re:The shok command shell by stormbrew on Sunday December 29, 2013 @01:53AM (#6978713)
I don't honestly find the pain point to shell scripting languages, in terms of programming them, to be that they don't look enough like 'real' programming languages. I think that on a basic level the way that posix shells work is quite natural for the tasks they're expected to perform. There's even a certain elegance to things like [ being (potentially) a program that behaves as any other would.

It is quite primitive as languages go, though, and has some ugly quirks, but I think it's a mistake to look at it and say it needs to be changed to be more like things not designed to treat running programs as primitives. I'd rather see something from someone who said "bash is great but could be so much better!" than someone who said "bash is TEERRRRRUUUBLE and we must replace it!"

That said what I want so much more than a new shell is one that isn't stuck letting me only reason about the machine I'm logged in on. There's been a few things that call themselves distributed shells, but they're really more orchestration tools.

Re:The shok command shell by kabdib on Sunday December 29, 2013 @11:51AM (#6980149)
In 35 years I've never been able to write more than ten lines of bash-level scripting without saying "Screw this, it's unreadable and unmaintainable" and writing the thing at hand in something else. (I think the longest non-trivial batch file I ever wrote was about 20 lines. I hated it). The "something else" changes with platform and decade, but usually it's native, or at least something like Python or C#.

Makefiles make me feel the same way, but here I have little choice. You can structure them "well" but they remain essentially undebuggable bits of hell that always seem to fall apart at the worst time.

I've worked with systems that had multi-thousand-line batch files and shell scripts, and my reaction has been "this crap is unsalvageable". A lot of those systems are still in production, and the people on them hate their lives. The code is a mass of spaghetti with a bunch of behavior modified by global and environment variables.

About 30 years ago I made the statement that "BASIC programs should self-destruct after 50 edits", as a way to encourage users of that language to move on to something more better, and to limit the damage that a "mission critical" 2 KSLOC hunk of bad code incurs. I maintain this would be desirable for bash and batch-like stuff, too...

Re:The shok command shell by hollerith on Sunday December 29, 2013 @01:28PM (#6980580)
I agree. (And booting a Debian system invokes many 10s of KSLOCs of the things, e.g., in /etc/init.d/.)
Re:The shok command shell by gbog on Sunday December 29, 2013 @03:06AM (#6978843)
I must be wired differently. I can get a for loop right the first time I write it in C, JavaScript, php, specially python, even if I do not use them daily. I think I never got a for loop right in bash. And ifs are always weird too. And letting a bracket be any thing is horrific, like if we were to use p as the full stop sign in English, and ( would be the name of a country: no thanks, remember brainfuck is a joke.
Re:The shok command shell by stormbrew on Sunday December 29, 2013 @03:31AM (#6978902)
It's not that [ can be anything (practically speaking it can't, actually, since it's often/usually a built-in that supersedes PATH). It's that [ obeys the rules of the 'language', where it is a program run on its arguments.

I agree that the surface syntax is bad. Unlike other languages with clear Algol influences it never got past thinking writing if backwards to end the block is clever. I'm all for fixing these sorts of things, if you're going to break compatibility with posix anyways.

Re:The shok command shell by xiaq on Sunday December 29, 2013 @03:05AM (#6978840)
Shells are what people use every day, so it's tempting to make more out of it. grep, sed and awk are clumsy tools, but they are more "within the reach" than python or ruby.

Also, you miss one particularly elegant aspect of shell programming: the pipeline. It's a powerful facility of concatenative programming, but most people haven't realize it. Try to write "find . -name '*.py' | xargs cat | wc -l" in other languages. You end up either with some parentheses or intermediate variables or a loop, and in any case, much longer code.

Re:The shok command shell by UNIXgod on Sunday December 29, 2013 @03:13AM (#6978865)
Yeah UNIX philosophy rocks! It's weird that they want a system shell and it not be POSIX. I don't need support for index arrays in a system shell interpreter.

Even erlang can be a shell and wrap around the system toolset making your basic shell scripts work concurrently.

For everyday usage the core ash shell is perfect for scripting and zsh csh or korn for interactive usage.

Re:The shok command shell by nfoz on Sunday December 29, 2013 @09:29AM (#6979603)
> For everyday usage the core ash shell is perfect for scripting

In my experience, most people have great difficulty correctly writing a simple loop to renames a set of files in a directory. I sumultaneously appreciate UNIX philosophy, and think the shell can be much improved by moving away from POSIX.

Re:The shok command shell by stormbrew on Sunday December 29, 2013 @03:35AM (#6978908)
The omission wasn't because I'm unaware, believe me. Maybe I just consider it so thoroughly fundamental as to be not worth noting.

This is where some of the warts on a higher level than syntax come in, though, to be fair. Your example above fails in confusing -- and maybe even dangerous, depending on the command at the end -- ways if there's spaces in the filenames. One thing I would like would be a more rigid sense of arguments vs. strings and how they come out of such situations. Having to add -print0 to find and --null to xargs to make it safe for that situation is tedious and unfriendly.

Re:The shok command shell by xiaq on Sunday December 29, 2013 @06:20AM (#6979238)
> This is where some of the warts on a higher level than syntax come in, though, to be fair. Your example above fails in confusing -- and maybe even dangerous, depending on the command at the end -- ways if there's spaces in the filenames. One thing I would like would be a more rigid sense of arguments vs. strings and how they come out of such situations. Having to add -print0 to find and --null to xargs to make it safe for that situation is tedious and unfriendly.

Yes, that's one of the problems I'm trying to solve :)

Powershell solves this by having pipelines pass .NET objects, but I found them too heavyweight.

Re:The shok command shell by stormbrew on Sunday December 29, 2013 @06:16PM (#6981967)
Agree that trying to turn it into an object pipeline is way too heavy.
Re:The shok command shell by MatmaRex on Sunday December 29, 2013 @06:52AM (#6979313)
map, fold and filter can approximate the pipeline pretty well. Personally I only use shell scripting when I actually want to record a set of commands I ran (or, well, when working in a shell); in all other cases I whip out proper tools.

Here's a comparison of code to do the same thing written in Ruby:

    Dir['**/*.py'].map{|f| File.readlines(f).length }.inject(:+)
    find . -name '*.py' | xargs cat | wc -l
That's 60 characters versus 39 (most of these are just because the "commands" are longer – and I don't think anyone would even try to argue that 'cat' or 'wc' is more readable than 'File.readlines' or 'length').

I ran them on Python 2.7's library directory and my version counted four lines more – I didn't investigate, but I think yours missed lines when cating files without trailing newline. I'd argue that's a bug in your code :)

Re:The shok command shell by xiaq on Sunday December 29, 2013 @07:13AM (#6979343)
Though it's mostly a matter of taste, I find pipelines simpler and more natural than method calls. Compare:

    xs.filter(p).map(f)
with

    filter p xs | map f
(Suppose filter and map are implemented such that they accept input either on the command line or from pipeline.)
Re:The shok command shell by Tyr42 on Sunday December 29, 2013 @09:16AM (#6979571)
Well, lets try Haskell syntax

    map f $ filter p xs
what, don't like the reverse order? That's fixable. If we define # as reverse function application, it's

    xs # filter p # map f
or

    filter p xs # map f
which is quite similar to what you are looking for.
Re:The shok command shell by icebraining on Sunday December 29, 2013 @05:22AM (#6979103)
> Try to write "find . -name '.py' | xargs cat | wc -l" in other languages.

  import pipe
  find(name='*.py') | xargs(cat) | wc().lines
The implementation of the functions is left as an exercise for the reader, but the syntax is valid.

https://github.com/JulienPalard/Pipe

Re:The shok command shell by stormbrew on Sunday December 29, 2013 @05:56AM (#6979188)
> The implementation of the functions is left as an exercise for the reader

This is kind of the point.

Re:The shok command shell by xiaq on Sunday December 29, 2013 @06:19AM (#6979234)
Yes it's possible in Python, but doing that means working against all idioms and zens of Python.

Languages are not only about what they make possible, but also about what they encourage.

Re:The shok command shell by norswap on Sunday December 29, 2013 @10:39AM (#6979858)
The problem with shell scripting is that it's not meant to be a programming language at all. Its philosophy is that anything that can be a program should be, with a few capabilities and builtins sprinkled on top.