bash. ()
: bash. ().
6.1
(, shell) UNIX-. - , ( ), UNIX. , 䳿 , .
. , ' . , , / . . , , ' . , (). , - . , .
:
- ;
- ;
- /;
- ();
- ;
- ;
- ;
- ;
- .
, UNIX. , , . , .
, . (, ) - , UNIX- ( bat- DOS).
, . , , ( csh bash), , ( Bourne). , , /etc/passwd . , ( chsh). UNIX :
Bourne Shell sh
Korn Shell ksh
C Shell csh
Bourne Again Shell bash
Public Domain Korn Shell pdksh
A Shell ash
Tcl Shell tclsh
X-Windows Shell wish
Remote Shell rsh
. . , Linux sh bash - (sh bash ). , , .
|
|
6.1.1 bash (bash)
Bash shell - Linux. Bourne Shell C Shell , Linux. bash ( /bin/bash /usr/bin/bash). , bash, "$".
6.1.2
.bash_profile ( autoexec.bat config.sys DOS), . .bash_profile bash. ³ . , , , . .bash_profile:
#.bash_profile (1)
# Get the aliases and functions (2)
if [ -f ~/.bashrc ]; then (3)
. ~/.bashrc (4)
fi (5)
# User specific environment and startup programs (6)
PATH=$PATH:$HOME/bin (7)
ENV=$HOME/.bashrc (8)
USERNAME="" (9)
export USERNAME ENV PATH (10)
, # (1, 2, 6), . , , .
3 , .bashrc. , then ( 4) - .bashrc . 5 - if-then.
7-9 . , PATH HOME - , . PATH (). bash .
, , export. , . export , ( 10).
bash .bashrc. ³ , . (). .bashrc , . .bashrc :
#.bashrc (1)
# User specific aliases and functions (2)
# Source global definitions (3)
if [ -f /etc/bashrc ]; then (4)
. /etc/bashrc (5)
fi (6)
set -o noclobber (7)
alias l='/bin/ls -al' (8)
, if-then ( 4-5). , - /etc/bashrc.
7 noclobber. ³ . , , , ' . noclobber , . - .
|
|
. , , , PATH. , ( ). (aliases). , ls, ( ). /bin/ls -al. - . 8 . , .
.bash_profile .bashrc , , , (.bash_history), (.bash_logout).
6.1.3
($), . , " " (Enter). : Linux , , , , -.
, , " - ". . , . , - " " , "\", . , :
1)
$ who; ps; echo JUNK MESSAGE
... ( who)
... ( ps)
JUNK MESSAGE ( echo)
2)
$ who
... ( who)
$ ps
... ( ps)
$ echo JUNK MESSAGE
JUNK MESSAGE ( echo)
3)
$ who; ps; echo JUNK \
>MESSAGE
... ( who)
... ( ps)
JUNK MESSAGE ( echo)
( ), , (). ϳ - , () . , (, .). :
[stud@localhost stud]$ cd /home
[stud@localhost home]$
^^^^
[stud@localhost stud]$ (cd /home)
[stud@localhost stud]$
^^^^
(cd /home) , . ϳ , . .
, ( !) . . :
$ elm `whoami`
whoami ', . ' elm ( ). e-mail.
|
|
bash . history. , . !! !n.
!! ()
!n n-
!-n n- , (!-1 !!)
!str , "str"
exit [expr]. ( ) expr. " " (Ctrl-D).
6.1.4
. , . UNIX, , . , - , . , script .
ps
echo end of script
, echo (). ps , . : . () , .
[stud@localhost stud]$. script
PID TTY STAT TIME COMMAND
269 1 S 0:00 /bin/login -- stud
270 1 S 0:00 bash
360 1 R 0:00 ps
end of script
[stud@localhost stud]$
, ps script, , 䳺 stud. ( 269) - (). (270) - . (360) - ps.
:
[stud@localhost stud]$ bash < script > outfile
[stud@localhost stud]$ cat outfile
PID TTY STAT TIME COMMAND
269 1 S 0:00 /bin/login -- stud
270 1 S 0:00 -bash
361 1 S 0:00 bash
362 1 R 0:00 ps
end of script
[stud@localhost stud]$
, . stud, bash ( 270), bash ( 361), ( ). , . . script, , ps ( 362), . , , ps, echo (Ctrl-D).
. () .
1. . # . , # , , "\".
2. . ϳ "" (#20h), "tab", " ". .
3. ³ . (;) . ʳ , - . (if while).
|
|
4. . , . , , , .
5. . , , . , , , , . . ʳ - , . , .
6.1.5
. :
* , ;
? . ʳ ;
[] ;
[^ ] , ;
{} . (), , , ;
~ .
, :
aaa, bbb, abc, cba, cccc
:
-
* aaa abc bbb cba cccc
??a aaa cba
*[b,c] abc bbb cccc
[a-z]?a aaa cba
*[^b,c] aaa cba
{a,b,c}bb abb bbb cbb
( , )
6.1.6 ()
. :
~ `! @ # $ % ^ & * () \ | { } [ ]; ' " < >?
, -, "\", . "" ASCII. ij , . :
$ touch a\ strange\ file
, - "a strange file".
( ) . , , "" , - . , , , . grep - .
$ grep [A-Z]* chap[12]
, . :
$ grep Array.c Bug.c Comp.c README chap1 chap2
, grep "Array.c" Bug.c, Comp.c, README, chap1, chap2. grep , :
$ grep "[A-Z]*" chap[12]
chap1 chap2.