The abstract of (chapter01 to chapter03)

本文介绍了Shell编程的基础知识,包括为何要学习Shell编程、如何创建并运行Shell脚本、掌握Shell脚本中的退出状态及各种特殊字符的使用方法。适用于初学者快速上手。

Chapter 1. Why Shell Programming?
The chapter answer why you need to grasp shell programming and answer when not to use shell scripts.

--------------------------------------------------------------
Chapter 2. Starting Off With a Sha-Bang
Start a file with a #!/XXX/XXX and make it executable.
#!/bin/sh
#!/bin/bash
#!/usr/bin/perl
#!/usr/bin/tcl
#!/bin/sed -f
#!/usr/awk -f

2.1. Invoking the script
1 make the script executable.
chmod 555 scriptname
chmod +rx scriptname
chmod u+rx scriptname
2 execute the shell script
./criptname arguments

---------------------------------------------------------------
Chapter 3. Exit and Exit Status
1 $? reads the exit status of the last command executed.$? is especially useful for testing the result of a command in a script.
Caution:
    Certain exit status codes have reverved meanings and should not be user-specified in a script.


__________________________________________________________________
Chapter 4. Special Characters
1 Comments: #
eg: # This line is a comment.
but the first hash(#) in the next statement is not a comment.
echo ${PATH#*:}        # Parameter substitution, not a comment.
Caution:
    Certain pattern matching operations also use the #.
2 command separator: ;
eg: echo hello; echo there
3 Terminator in a case option:    ;;[double semicolon]
eg: case "$variable" in
    abc) echo "$variable = abc";;
    xyz) echo "$variable = xyz";;
esac
3 dot command: .
1st: A dot is equivalent to source. This is a bash builtin.
2nd: In a regular expression, a dot matches a single character.
3rd: A dot is the filename prefilx of a "hidden" file,  a file that an ls will not normally show.
4 patial quoting: "[double quote]
5 full quoting: '[single quote]
6 comma operator: ,
7 escap: /X
8 Filename path separator: /
9 command substitution: `
10 null command: :
11 reverse (or negate) the sense of a test or exit status: !
12 wild card: *
13 wild card(single character): ?
14 variable substitution: $
Caution:
    In a regular expression, a $ matches the end of a line.
15 Parameter substitution: ${}
16 positional parameters: $*, $@
17 command group: ()
eg: (a=hello; echo $a)
18 brace expansion: {}
eg: grep linux file*.{txt, htm*}
# in the files "fileA.txt", "file2.txt", "fileR.html", "file-87.htm", etc.
18: block of code: {}
eg: bash$ {local a; a=123}
19 test: []
Test expression between[]. Note that [ is part of the shell builtin test, not a link to the external command /usr/bin/test.
20 test: [[]]
Test expression between [[]](shell keyword).
21 integer expansion: (())
Expand and evaluate integer expression between(()).
22 redirection: >>&>><
23 pipe: |
24 force redirection: >1
25 run job in background: &
26 redirection from/to stdin or stdout: -[dash]
27 previous working directory: - [dash]
28 Minus: -
29 Equals: =
30 Plus: +
31 modulo: %
32 home directory: ~
33 current working directory: ~+
34 previous working directory: ~-
35 Control Characters
    Ctl-C: Terminate a foreground job.
    Ctl-D: Log out from a shell(simial to exit or EOF)
    Ctl-6: "BEL"(beep)
    Ctl-H: Backspace
    Ctl-J: Carriage return
    Ctl-M: Newline
    Ctl-U: Erase a line of input
    Ctl-Z: Pause a foreground
36 Whitespace: functions as a separator, separating command or variables.
Note: $IFS, the special variable separating fields of input to certain commands, defaults to whitespace.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值