Chinaunix首页 | 论坛 | 博客
  • 博客访问: 913028
  • 博文数量: 132
  • 博客积分: 9976
  • 博客等级: 中将
  • 技术积分: 1781
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-30 20:40
文章分类

全部博文(132)

文章存档

2013年(1)

2011年(1)

2010年(15)

2009年(77)

2008年(36)

2007年(2)

我的朋友

分类:

2008-12-19 14:27:54


My_Shell_Learn of "Learning the bash, 3rd Edition"

声明:
   本文章里面的所有内容作者保留所有权限,禁止用于商业目的, 只供个人学习使用。
但可以随意转载, 不过请保留这段文字。

作者:
   Chen-Jian-151x

===========================================================================
chapter-0
===========================================================================
1. 查看 Bash Shell 版本方法:
   # echo $BASH_VERSION
   # bash --version
   note:
   #  -v        Print shell input lines as they are read.
   # bash -v # 会打印出所有的全局变量和全局函数。

2. Directory manipulation, with the pushd, popd, and dirs commands
3. Job control, include the fg and bg commands and the ability to stop jobs with  
   CTRL-Z


===========================================================================
chapter-1

1.1 What Is a Shell ?

chj@linux-xzlr:chap1\> cat char_list
d
e
f
a
b
x
s
tchj@linux-xzlr:chap1\> sort -n char_list
a
b
d
e
f
s
t
x
chj@linux-xzlr:chap1\>

comments:
       -n, --numeric-sort
              compare according to string numerical value


1.4 Getting bash

  查看当前 shell 类型
    # echo $SHELL

  To install bash as your login shell, type chsh bash-name, where bash-name
is the response you got to your whereis command(or whatever worked). For example:
  # chsh /usr/local/bin/bash

1.6 Brace Expansion

cjash@linux-h3i2:files\> echo b{ed,olt,ar}s
beds bolts bars
cjash@linux-h3i2:files\> echo b{ar{d,n,k},ed}s
bards barns barks beds
cjash@linux-h3i2:files\> echo {2..5}
2 3 4 5
cjash@linux-h3i2:files\> echo {d..h}
d e f g h
cjash@linux-h3i2:files\> echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
cjash@linux-h3i2:files\>


1.9 Special characters

(

Start subshell

)

End subshell


{

Start command block

}

End command block



`

Strong quote

<">

Weak quote



Table 1-7. Control keys

Control key

stty name

Function description

CTRL-C

intr

Stop current command

CTRL-D

eof

End of input

CTRL-\

quit

Stop current command if CTRL-C doesn't work

CTRL-S

stop

Halt output to screen

CTRL-Q

 

Restart output to screen

DEL or CTRL-?

erase

Erase last character

CTRL-U

kill

Erase entire command line

CTRL-Z

susp

Suspend current command (see )



stty -a to see all control keys;

the difference of C-C and C-\
Sometimes CTRL-C doesn't work; in that case, if you really want to stop a job, try CTRL-\. But don't just type CTRL-\; always try CTRL-C first! explains why in detail. For now, suffice it to say that CTRL-C gives the running job more of a chance to clean up before exiting, so that files and other resources are not left in funny states.

C-S, C-Q
CTRL-S and CTRL-Q are called flow-control characters. They represent an antiquated way of stopping and restarting the flow of output from one device to another (e.g., from the computer to your terminal) that was useful when the speed of such output was low. They are rather obsolete in these days of high-speed networks. In fact, under the latter conditions, CTRL-S and CTRL-Q are basically a nuisance. The only thing you really need to know about them is that if your screen output becomes "stuck," then you may have hit CTRL-S by accident. Type CTRL-Q to restart the output; any keys you may have hit in between will then take effect.

C-H
The final group of control characters gives you rudimentary ways to edit your command line. DEL acts as a backspace key (in fact, some systems use the actual BACKSPACE or CTRL-H key as "erase" instead of DEL); CTRL-U erases the entire line and lets you start over. Again, these have been superseded. The next chapter will look at bash's editing modes, which are among its most useful features and far more powerful than the limited editing capabilities described here.

C-/, to undo

===========================================================================

===========================================================================
chapter-2

1. Enabling Command-Line Editing

bash initially starts interactively with emacs-mode as the default (unless you have started bash with the -noediting option; see ). There are two ways to enter either editing mode while in the shell. First, you can use the set command:

-nolineediting in versions of bash prior to 2.0.

$ 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. We will look at this method later in this chapter.

You will find that the vi- and emacs-editing modes are good at emulating the basic commands of these editors, but not their advanced features; their main purpose is to let you transfer "keyboard habits" from your favorite editor to the shell. fc is quite a powerful facility; it is mainly meant to supplant C shell history and as an "escape hatch" for users of editors other than vi or emacs. Therefore the section on fc is mainly recommended to C shell users and those who don't use either standard editor.

2. C-R

CTRL-R

Search backward


You sigh heavily and go back and find the fgrep command you typed in an hour ago. To do this, you type CTRL-R; whatever was on the line will disappear and be replaced by (reverse-i-search)`':. Then type fgrep, and you will see this:

$ (reverse-i-search)`fgrep': fgrep -l Duchess <~cam/book/ \

alice_in_wonderland[]

The shell dynamically searches back through the command history each time you type a letter, looking for the current substring in the previous commands. In this example, when you typed f the shell would have printed the most recent command in the history with that letter in it. As you typed more letters, the shell narrowed the search until you ended up with the line displayed above. Of course, this may not have been the particular line you wanted. Typing CTRL-R again makes the shell search further back in the history list for a line with "fgrep" in it. If the shell doesn't find the substring again, it will beep.

If you try the fgrep command by hitting RETURN, two things will happen. First, of course, the command will run. Second, this line will be entered into the history list at the end, and your "current line" will be at the end as well. You will no longer be somewhere else in the command history.

Another handy trick to save typing if you have already done a search is to type CTRL-R twice in a row. This recalls the previous search string you typed in.

3.
Table 2-15. Event designators

Command

Description

!

Start a history substitution

!!

Refers to the last command

!n

Refers to command line n

!-n

Refers to the current command line minus n

!string

Refers to the most recent command starting with string

!?string?

Refers to the most recent command containing string; the ending ? is optional

^string1^string2

Repeat the last command, replacing string1 with string2



===========================================================================

===========================================================================
chapter-0
===========================================================================

===========================================================================
chapter-0
===========================================================================

===========================================================================
chapter-0
===========================================================================

===========================================================================
chapter-0
===========================================================================


===========================================================================
chapter-0
===========================================================================


===========================================================================
chapter-0
===========================================================================


===========================================================================
chapter-0
===========================================================================


===========================================================================
chapter-0
===========================================================================


===========================================================================
chapter-0
===========================================================================


===========================================================================
chapter-0
===========================================================================


===========================================================================
chapter-0
===========================================================================


阅读(838) | 评论(0) | 转发(0) |
0

上一篇:quilt 使用

下一篇:什么是ccache

给主人留下些什么吧!~~