简体   繁体   中英

Scripting language shells?

Are there any software packages or projects that provide the scripting language shells? I know there's csh for C programmers although not in a sense that it's primarily for programming, but for navigation and system administration. I was wondering if there is something inverted for this purpose? Ie user logs into a shell that's primarily for programming and then for navigation (something like irb in ruby, but with navigation capabilities)?

I think you're misinformed if you think csh (tcsh) is for C programmers. It's just a shell like bash or ash or dash or ksh or zsh.

The R language provides a reasonably functional internal environment, complete with the ability to save/restore the "workspace" (your variables).

Python has a built-in interpreter, as does Maxima, and some Lisp/Scheme versions, plus you already mentioned irb.

You could also view vim or emacs as the type of programmer-centric shell you're talking about; both can be hooked up to run navigation commands and sysadmin-type stuff without forcing you to leave the editor.

I think the real answer to your question is "powerful shells provide their own scripting language".

System navigation (and administrative tasks) are a really different application than programming, and it's hard to find a single shell that does both well. However, I'm guessing that what you're really asking for is a shell that

  1. Lets you easily load the contents of a file and manipulate those contents in-process and with more dexterity than you get using bash and standard unix utilities.
  2. In addition you want the convenience of accessing some of the normal commands for moving files around and navigating the file system.

The good news is that the standard scripting languages (eg Ruby, Perl) were meant to do #1 really well, and it's not hard to write/find a library to do #2 any of these langauges.

Because Ruby is what I'm familiar with, I'm going to give you a more concrete example of how you might accomplish this using Ruby.

To do this in Ruby, you would use irb (the Ruby REPL), and the FileUtils module which is part of Ruby's standard library.

To do this, start irb , then run

require 'fileutils'
include FileUtils

(you can put this in .irbrc if you'd like, but I'm not sure I'd recommend that.)

this allows you to have access to a number of the normal file manipulation commands through easy Ruby syntax. You can run other Ruby commands automatically yourself. To run other commands on your system, you're going to have to call them with system .

FileUtils doesn't include an ls command, because it wasn't really meant to be used interactively, so you'll need to write your own. I don't know a way to get good job control at all (that's not to say you couldn't write something though).

The only thing I warn you is that this workflow will be very different than other UNIX users, so you might want to think about being such a nonconformist is worth it, or whether you'd rather build experience that meshes well with other UNIX admins' working styles. It's probably better to get used to the core UNIX utils and the Bourne shell scripting language. (You could learn C-Shell if you want, but there is a well-known FAQ explaining the disadvantages of the C-shell for programming .)

You may want to take a look at IPython . It is an interactive Python shell (with filesystem navigation alongside other nice features) and it also provides a system shell profile to optimize its behavior for system shell usage.

Tcl's interpreter, tclsh, is really designed to be a shell. In fact, unlike Ruby where the interactive and non interactive shell are separate, tclsh works just like traditional shells like bash: if run without a script it enters interactive mode but given a script it enters batch mode.

But, it does suck in that it doesn't have readline built-in. So no up-arrow history or tab completion etc. But you can always run it using rlwrap:

rlwrap tclsh

which should give you readline capabilities.

However, I wasn't satisfied (partly because my system at the time didn't have rlwrap and partly because there were a few more features I wanted). So I wrote my own implementation of history and tab completion etc. Checkout my original Pure-tcl readline or the improved Pure-tcl readline2 .

It really does act like an interactive shell complete with auto-executing external executables if a tcl command is unknown. And you can even execute interactive programs like vi, emacs or lynx from it. Because it automatically falls back to executing external commands, you can mix tcl and shell like:

foreach x [split [ps aux | grep apache] \n] {
    puts [lindex $x 1]
}

This is great because tcl's syntax is much saner compared to bash and sh (ever tried to get out of '"\\"\\\\\\\\"\\ quoting hell in bash?). I personally like tcl but tcl is kind of a love-it-or-hate-it language. People who get it really love it and people who don't really hate it.

But even if you don't quite like tcl syntax I'd suggest you give it a try for this specific application because unlike other languages tcl really is designed to be used more as a command language than a programming language. Read I can't believe I'm praising Tcl for some of the reasons why.

CSH has nothing to do with C programming. It's serves the same functions as the Bourne Shell about equally well, but uses different syntax.

If you want C interpreter, I suggest using cint, which is part of CERN's ROOT system. But keep in mind that it's not useful in the least for system administration and navigation.

我敢肯定,通过一点点工作,您可以进一步扩展Devel :: REPL (Perl)以提供对gnu coreutils的访问,

Bash has lots of programming features that aren't ordinarily acknowledged, for example arrays and string manipulation options when expanding a shell variable. Some shells, like zsh or ksh have greatly improved programming features compared to the most common shells (namely bash or tcsh.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM