JShell
(Andrew Van Kirk)
Version
1.0
A Unix-Like Shell
Written in Java
Users
Guide
Welcome to Jshell! This is the Users Manual. If you like Java a lot, you may want the Programmer's Manual.
This is where you learn how to use JShell.
Starting JShell
Were going to assume that you
have all the necessary Java stuff installed and can compile the *.java files for
JShell. If you
cant, you need more help than I can give you here. Once compiled, just type
java JShell
at your normal command prompt. In a brief moment, the JShell
prompt will appear. Now youre ready to
get to work.
JShell as a standard shell
The standard JShell prompt (and as of version 1.0 this is the only
prompt) is:
prompt$
JShell, for the most part, behaves exactly like any other
standard Unix or Linux shell (such as csh, bash, etc).
Below you will find a list of all commands, their specified arguments,
whether or not they accept piped input, etc.
Where then syntax is markedly different from a standard shell command,
that difference is in italics.
There are three particular
non-command inputs that are possible:
Comments:
Comments are any line entered at the prompt that begins with #. As long as the first character of the line is
#, the entire line, including any elements which would be commands, become
comments. Exampls
#this is a comment
#so is this
#cat date cut 10 foo.txt
#all that was a comment to
WhiteSpace: No matter how much whitespace is entered at
the prompt, it means nothing. It will be
ignored.
Non-commands: If the first term of a line of input to the shell is not a recognized
command, and error will be returned.
Nothing else will be done.
Now for the Commands:
|
Command |
Arguments |
Example(s) |
PipedData(y/n) |
Description |
|
logout |
None |
logout |
N |
Exit from JShell |
|
echo |
[string
] |
echo the cow echo cat foo.txt |
N |
Outputs its arguments,
separated by a space and terminated by a newline |
|
date |
None |
date |
N |
Outputs the date and time |
|
cat |
[file
] |
cat JShell.java cat JShell.java
junk date | cat |
Y |
Outputs each file (or
piped stream) in sequence; If no input is given, cat reads date from Standard.in (keyboard most cases) |
|
head |
[number]
[file
] |
cat junk | head 2 head 2 JShell.java |
Y |
Outputs the first number
of lines of each file |
|
tail |
[number]
[file
] |
cat junk | tail 2 tail 2 JShell.java |
Y |
Outputs the last number of
lines of each file |
|
wc |
[file
] |
wc junk cat junk junk2 | wc |
Y |
Outputs a count of lines,
words, and characters in each file |
|
cut |
[number] [file
] |
cut 2 junk cut 2 junk junk2 |
Y |
Outputs given field from each line of specified
file, where fields are delimited by spaces |
|
grep |
[string] [file
] |
grep fun junk cat junk2 | grep fun |
Y |
Searches each file for
given string and outputs all lines that contain that string |
|
sort |
[file
] |
sort junk2 junk sort junk junk junk |
Y |
Sorts lines of all named
files together and outputs result |
|
uniq |
[file
] |
uniq junk uniq junk junk junk |
Y |
Read each file comparing
lines, outputs one and only one copy of each input line |
|
setenv |
[string
] |
setenv COURSE cps setenv EXT .java |
N |
Maps first string to
remaining arguments, outputs nothing |
|
printenv |
[string] |
printenv EXT |
N |
Outputs environment
variable corresponding to string |
|
unsetenv |
[string] |
unsetenv COURSE |
N |
Removes variable name from
environment, outputs nothing |
|
cd |
[directory] |
cd /home/andrew cd tmp |
N |
Change working directory
to given directory, outputs nothing |
|
pwd |
none |
pwd |
N |
outputs current working
directory |
|
pushd |
[directory] |
pushd /home/andrew pushd cps108 |
N |
Push current directory
onto directory stack, change working directory to new top directory, outputs
nothing |
|
popd |
none |
popd |
n |
Pop directory from the
directory stack, change working directory to new top directory, outputs
nothing |
|
dirs |
none |
dirs |
n |
Outputs current working directory,
then contents of directory stack |
|
ls |
[file
] OR none |
Ls Ls cat.java Ls /home/andrew |
y |
For each file that is a
directory, outputs the contents of the directory; for each file that is an
ordinary file, outputs its name (if called with no arguments, outputs all
files and directories in current working directory) |
|
du |
[file
] OR none |
du du cat.java du /home/andrew |
y |
Outputs disk usage if file is an ordinary file,
total size if file is a directory (if called with now arguments, outputs disk
usage of the current working directory and all subclasses) NB actually
returns file size in kilobytes, not disk usage |
Final Notes:
Piping and Redirecting I/O: Piping and I/O redirection is done exactly as it
done in Unix, i.e.
Ls | wc //piping
Cat a b c > out //output redirection
Cut 2 < junk //input redirection
Environment Variables: In regards to storing environment variables, see
command above. To use their
value in a string, preceed the name of the variable by
a $ character. Example:
setenv EXT .java // set variable
ls JShell$EXT //
expands to ls JShell.java
Thank you for using JShell, v1.0
Last modified