⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jshell.html

📁 用JAVA写的shell程序
💻 HTML
📖 第 1 页 / 共 2 页
字号:
                    </tr>
                    <tr>
                        <td>jshell.lines</td>
                        <td>If JShell pauses after each page of output (see jshell.page), then jshell.lines determines how many lines of output constitute a page.</td>
                    </tr>
                    <tr>
                        <td>jshell.page</td>
                        <td>Indicates whether jshell pauses after each page of output.</td>
                    </tr>
                    <tr>
                        <td>jshell.prompt</td>
                        <td>The prompt character.</td>
                    </tr>
                </table>
            
        <hr><h1><a name="section7">7. Strings</a></h1>
                <p>
Any sequence of characters (possibly including escaped
characters) entered on the command line is a string. Strings may
be unquoted, quoted with a single-quote character (') or quoted
with a double-quote character ("). The rules for processing
strings come from UNIX's sh shell:
                </p>
                <table cellpadding="5">
                    <tr>
                        <td></td>
                        <td>Unquoted string</td>
                        <td>Single-quoted string</td>
                        <td>Double-quoted string</td>
                    </tr>
                    <tr>
                        <td>Escapes</td>
                        <td>Processed</td>
                        <td>Ignored</td>
                        <td>Ignored</td>
                    </tr>
                    <tr>
                        <td>Glob Patterns</td>
                        <td>Expanded</td>
                        <td>Not expanded</td>
                        <td>Not expanded</td>
                    </tr>
                    <tr>
                        <td>Environment variables</td>
                        <td>Evaluated</td>
                        <td>Not evaluated</td>
                        <td>Evaluated</td>
                    </tr>
                </table>
                <p>
Examples:
                </p>
                <p>
1) These strings:
                </p>
                <pre>
        a\bc    'a\bc'  "a\bc"
                </pre>
                <p>
evaluate to abc, a\bc and a\bc respectively. (The last two
strings contain four characters each, and the second character is
the backslash.)
                </p>
                <p>
2) This command:
                </p>
                <pre>
        ls *.java 
                </pre>
                <p>
lists all the java sources in the current directory. But these
commands:
                </p>
                <pre>
        ls '*.java'
        ls "*.java"
                </pre>
                <p>
list a file named "*.java" if it exists.
                </p>
            
        <hr><h1><a name="section8">8. Piping</a></h1>
                <p>
UNIX-style piping can be done using the ^ character. (This
character was chosen instead of the more traditional | because |
is not on the 5mx keyboard.)
                </p>
            
        <hr><h1><a name="section9">9. Redirection</a></h1>
                <p>
UNIX-style redirection can be done for standard output (not error
output currently):
                </p>
                <table cellpadding="5">
                    <tr>
                        <td>&lt;</td>
                        <td>redirects input.</td>
                    </tr>
                    <tr>
                        <td>&gt;</td>
                        <td>redirects output, overwriting the target file.</td>
                    </tr>
                    <tr>
                        <td>&gt;&gt;</td>
                        <td>redirects output, appending to the target file.</td>
                    </tr>
                </table>
            
        <hr><h1><a name="section10">10. Background tasks</a></h1>
                <p>
A command can be run in the background by typing &amp; at the end of
the command. For example, to get a recursive listing of your
entire file system in files.txt as a background job, you can do
this:
                </p>
                <pre>
        200&gt; ls :lR &gt; files.txt &amp;
                </pre>
                <p>
If you enter multiple commands on a line, the entire set of
commands runs in the background.
                </p>
                <p>
You can observe currently running jobs by using the jobs command,
e.g.
                </p>
                <pre>
        201&gt; jobs
        123: javac *.java &gt; errors.txt &amp;
        157: ls :lR &gt; files.txt &amp;
                </pre>
                <p>
You can kill a background job by using the kill command. E.g.,
here's how you would kill the recursive listing of the file
system:
                </p>
                <pre>
        202&gt; kill 157
                </pre>
                <p>
There is currently no support for putting a foreground job into
the background.
                </p>
            
        <hr><h1><a name="section11">11. Command recall</a></h1>
                <p>
The history command can be used to find out about the last few
commands you've executed. E.g.
                </p>
                <pre>
        3&gt; history
        0: pwd
        1: cd /foo/bar
        2: javac *.java &gt; errs.txt &amp;
                </pre>
                <p>
You can rerun the previous command by typing !!, or any other
command by using it's number, e.g. !3.
                </p>
                <p>
By default, the last 100 commands are saved. You can change this
limit by modifying the variable jshell.history_size. You can
limit the amount of history shown to the n most recent commands
by passing n to the history command, e.g.
                </p>
                <pre>
        301&gt; history 2
        299: ls *.java
        300: rm *.class
                </pre>
            
        <hr><h1><a name="section12">12. Command usage</a></h1>
                <p>
Help on any command can be obtained by using the help
command. help takes one argument, the name of the builtin JShell
command, (i.e. the name of a class in the package
jshell.command). Example:
                </p>
                <pre>
        400&gt; help cp
        cp source ... destination
            Copies source files to destination.
            - If there are multiple sources, the destination
              must be a directory.
            - Directories are not copied by default.
            - Use the -R flag to copy recursively.
                </pre>
Here is a complete list of the builtin commands:
                <ul>
                    <li>cat</li>
                    <li>cd</li>
                    <li>cp</li>
                    <li>dirs</li>
                    <li>echo</li>
                    <li>env</li>
                    <li>exit</li>
                    <li>gc</li>
                    <li>help</li>
                    <li>history</li>
                    <li>javac</li>
                    <li>jobs</li>
                    <li>kill</li>
                    <li>ls</li>
                    <li>mkdir</li>
                    <li>popd</li>
                    <li>pushd</li>
                    <li>pwd</li>
                    <li>rm</li>
                    <li>save</li>
                    <li>set</li>
                </ul>
            
        <hr><h1><a name="section13">13. Extending JShell</a></h1>
                <p>
JShell can run Java applications (i.e. Java classes that have a public
static void main(String[] method), and JShell commands. A JShell
command is a Java class with the following characteristics:
                </p>
                <ul>
                    <li>It extends jshell.Command.</li>
                    <li>It defines two methods:</li>
                    <ul>
                        <pre>
                        <li>public void execute(String[] args)</li>
                        <li>public void usage()</li>
                        </pre>
                    </ul>
                    <li>
Input, output and error streams are accessed
using the methods in(), out() and err() respectively.
                    </li>
                    <li>
It calls checkForInterruption() periodically,
(so that it can be killed from the command line
in a timely manner).
                    </li>
                </ul>
                <p>
A JShell command can be run by giving the fully qualified
class name, followed by its arguments. For example, if you
have written a class, com.mycompany.MyClass, which takes
one integer argument, you could do this:
                </p>
                <pre>
        123&gt; com.mycompany.MyClass 419
                </pre>
                <p>
Command-line arguments (from the JShell command line) are passed
to execute's args argument. usage() prints out a usage message.
                </p>
                <p>
JShell commands can be connected using pipes, and input and
output can be redirected.
                </p>
                <p>
Java applications run from JShell are problematic in a few
ways. First, they can call System.exit which causes JShell to
terminate immediately. Second, piping and redirection are not
possible. JShell creates input and output streams for use by
commands, but applications use System.in, System.err and
System.out directly. It isn't clear how to, for example, pipe the
output of one Java application to another when both use System.in
and System.out. Another problem is that Java applications may not
ever yield control, which means that they cannot be killed. (The
kill commands uses Thread.interrupt, not Thread.stop which is
deprecated in JDK 1.2 and can produce unpredictable results.)
                </p>
                <p>
It is sometimes convenient to use JShell to run Java commands,
but in general, if you want to write a class to be run from
JShell, you should write it as a command, following the
guidelines described above. (Or look at any source in the
jshell.command package, to see how JShell's builtin commands are
coded.)
                </p>
            
        <hr><h1><a name="section14">14. Known problems</a></h1>
                <ul>
                    <li>
javac flags don't work. You can compile files (e.g. javac *.java),
but don't try specifying any flags to the javac command.
                    </li>
                    <li>
If you run the command "echo $foo" where foo is an undefined
variable, echo will simply echo what you type (twice, in
fact). This is actually documented behavior (see "help echo"),
since "echo $foo" is equivalent to "echo" when foo is
undefined. Unfortunately, I know of no way to regain useful
control of JShell once this happens. You'll have to kill
JShell, e.g. using Shift-Ctrl-Fn-K. 
                    </li>
                </ul>
            
        <hr><h1><a name="section15">15. Helping out with JShell</a></h1>
                <p>
JShell is an open-source project and contributions are welcome.
Contributions can take the form of bug-fixes, new commands,
suggestions, new features in the JShell core, etc.  I'll act as
coordinator and release updates periodically. If you want to help
out but don't know what to work on, contact me at
<a href="mailto:jao@mediaone.net">jao@mediaone.net</a>.
If you send me your email address, I'll keep
you posted on JShell developments.
                </p>
                <p>
Here are some projects that need to be done:
                </p>
                <ul>
                    <li>
Platform-specific documentation and help facilities (especially
EPOC, but also Windows and Unix).
                    </li>
                    <li>
                        Commands:
                        <ul>
                            <li>mv: Put a general-purpose copy and delete implementation in jshell.OS (and called from jshell.command.mv). Allow OS-specific overrides, e.g. to spawn an mv command.</li>
                            <li>grep: based on glob patterns, not regular expressions.</li>
                            <li>chmod</li>
                            <li>tail</li>
                            <li>head</li>
                            <li>sed</li>
                            <li>awk</li>
                            <li>wc</li>
                        </ul>
                    </li>
                    <li>
A JShell scripting language: Be able to read JShell commands from a text file; Add simple control constructs.
                    </li>
                    <li>
An integrated editor.
                    </li>
                    <li>
An awt-based console to replace the standard Java console. This
should permit more flexible keyboard handling and enable things
such as emacs key bindings, command recall using arrow keys, and
suspending foreground jobs.
                    </li>
                    <li>
Get rid of all the CommandElementExpander$Transition* and
LexerAutomaton$Transition classes. They greatly increase JShell's
footprint. The functionality of these classes could be coded in a
much more memory-efficient way, with only a slight loss in
program readability.
                    </li>
                    <li>
Support JShell on other platforms.
                    </li>
                    <li>
An XSLT style sheet to generate plain-text documentation.
                    </li>
                </ul>
            
    </body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -