A self-made shell command , written by Java.
-
echo
-
grep
-
pwd
-
ls
-
cd
-
cat
-
mkdir
-
cp
-
echo | grep
pipeline operation
-
Echo and grep commands do not implement quotes match
-
The command
|
is not implemented, this requires pipelined programming -
Grep command does not use regular expressions is what needed to be improved
-
A special Pwd class is used to maintain the work path, instead of using the system work path
专门用到了一个Pwd类维护工作路径,而非使用系统的工作路径
System.getProperty("user.dir")
reason:
Calling System.setProperty("user.dir","xxx") to modify user.dir can affect the subsequent creation of java.io.File and java.nio.file.path,but it will not affect java.io.FileOutputStream, java.lang.Process,etc. That is, the current directory is stiill for writing files, child Process etc, which will not be modified with the pace of the modification of system attributes.
调用System.setProperty(" user.dir ", " xxx ")修改user.dir后,能影响java.io.File和java.nio.file.Path的后续创建,但不会影响java.io.FileOutputStream、java.lang.Process等,即写入文件、子进程等当前目录还是进程启动时的目录,不会随系统属性的修改而修改。
-
A custom Exception class: ArgumentsException is created, and the utility class CheckArguments is used to detect input parameters.
建立了一个自定义的异常类ArgumentsException,并使用工具类CheckArguments检测输入参数,方便有效,逼格也高。
-
Handle the problem of \n cannot be escaped to newLine
\n不能转义为换行符的问题。
In java,
\\
means : I want to insert a regular expression backslash, so the characters after it have a special meaning.(While other languages only need a back)在Java中,
\\
表示:我要插入一个正则表达式的反斜线,所以其后的字符具有特殊的意义。(而其他语言只需要一个反斜杠即可)So, in other languages (such as Perl), a backslash
\
is sufficient to escape, while in Java regular expressions need two backslash to be parsed into Escape effect.所以,在其他的语言中(如Perl),一个反斜杠
\
就足以具有转义的作用,而在 Java 中正则表达式中则需要有两个反斜杠才能被解析为其他语言中的转义作用。We can also simply understand that in Java's regular expressions, tow
\\
represent one\
, which is the reason why regular expression representing a number is\\d
and a normal backslash is\\\\
.也可以简单的理解在 Java 的正则表达式中,两个
\\
代表其他语言中的一个\
,这也就是为什么表示一位数字的正则表达式是\\d
,而表示一个普通的反斜杠是\\\\
。
JShell by https://github.com/Chao-Yin-Github/JShell is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.