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.
The abstract of (chapter01 to chapter03)
最新推荐文章于 2025-09-06 23:40:33 发布
