Chapter2. Command-Line

This is exactly what bash allows you to do. It has editing modes that allow you to edit command lines with editing commands similar to those of the two most popular UNIX editors, vi and emacs. It also provides a much-extended analog to the C shell history mechanism called fc (for fix command) that, among other things, allows you to use your favorite editor directly for editing your command lines. To round things out, bash also provides the original C shell history mechanism.

bash initially starts interactively with emacs-mode as the default, First, you can use the set command:

$ set -o emacs

or:

$ set -o vi

The second way of selecting the editing mode is to set a readline variable in the file .inputrc.

vi Editing Mode

Editing commands in vi input mode

CommandDescription
DELDelete previous character
CTRL-WErase previous word (i.e., erase until a blank)
CTRL-VQuote the next character
ESCEnter control mode (see below)

Basic vi control mode commands

CommandDescription
hMove left one character
lMove right one character
wMove right one word
bMove left one word
WMove to beginning of next non-blank word
BMove to beginning of preceding non-blank word
eMove to end of current word
EMove to end of current non-blank word
0Move to beginning of line
^Move to first non-blank character in line
$Move to end of line

Commands for entering vi input mode

CommandDescription
iText inserted before current character (insert)
aText inserted after current character (append)
IText inserted at beginning of line
AText inserted at end of line
RText overwrites existing text

Abbreviations for vi-mode delete commands

CommandDescription
DEquivalent to d$ (delete to end of line)
ddEquivalent to 0d$ (delete entire line)
CEquivalent to c$ (delete to end of line, enter input mode)
ccEquivalent to 0c$ (delete entire line, enter input mode)
XEquivalent to dl (delete character backwards)
xEquivalent to dh (delete character forwards)

vi control mode commands for searching the command history

CommandDescription
k or -Move backward one line
j or +Move forward one line
GMove to line given by repeat count
/stringSearch backward for string
?stringSearch forward for string
nRepeat search in same direction as previous
NRepeat search in opposite direction of previous

** Miscellaneous vi-mode commands**

CommandDescription
~Invert (twiddle) case of current character(s)
-Append last word of previous command, enter input mode
CTRL-LClear the screen and redraw the current line on it; good for when your screen becomes garbled
#Prepend # (comment character) to the line and send it to the history list; useful for saving a command to be executed later without having to retype it

The readline Startup File

The default startup file is called .inputrc and must exist in your home directory if you wish to customize readline. You can change the default filename by setting the environment variable INPUTRC

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
7.main方法参数的使用。阅读下面的代码。 --------程序清单------------------------------------------------------------------------------------------------------------ package chapter06; public class CommandLine { public static void main(String[] args) { if (args.length == 0) { System.out.println("Hello, welcome to Java!"); } else { switch (args[0]) { case "-draw" -> { for (int i = 0; i < 3; i++) { for (int j = i; j < 3; j++) System.out.print("*"); System.out.println(); } } case "-add" -> {// + int sum = 0; for (int i = 1; i < args.length; i++) { int num = Integer.parseInt(args[i]); sum += num; if (i != 1 && num > 0) System.out.print("+"); System.out.print(args[i]); } System.out.println("=" + sum); } default -> { System.out.println("no such command-line option"); } } } } } --------------------------------------------------------------------------------------------------------------------------------- 以下操作都在该类源文件所在的文件夹下。 (a)(2分)编译完该类后,如果在终端通过输入命令“java chapter06.CommandLine -cdl Wenzhou”运行该类,此时main方法的形参args其每个元素的值是什么? (b)(16分)分别通过以下命令运行该程序,其输出结果是什么?请简单说明你的理由(没有理由不给分)。 java chapter06.CommandLine -add 12 31 44 -1 -2 java chapter06.CommandLine -draw java chapter06.CommandLine java chapter06.CommandLine -cdl (c)(2分)在Eclipse里设置运行配置,然后得到(b)中第1条命令运行效果并截图。 答:
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值