15 Bash
其实你应该把 bash 理解成一个跟桌面系统一样强大的程序。
15.1 trouble shooting
- disable XON/XOFF to avoid conflict with search forward
stty -ixon # you can put it into ~/.bashrcwhen your cursor disappear,
echo -en "\e[?25h"use
\tin regexp
cat filename | sed -nE $'/pattern\t/p'
cat filename | sed -nE '/pattern'$'\t''/p' # same as above15.2 shortcut
| ctrl+a/e | go to begin/end |
| ctrl+u/k | delete to begin/end |
| ctrl+insert | copy |
| shift+insert | paste |
| ctrl+r | search backward |
| ctrl+s | search forward |
| left/right | select current line |
| enter | excute current line |
15.3 job control
One can use find / as example since it runs for a long time.
fg %nbrings a job into the foregroundbg %nrestarts a suspended background jobjobslists jobs in the backgroundkill %nterminates a job
其中,n 是 job nubmer,fg, bg 默认为当前 job. more ways to specify a job.
So there are basically two ways to run a process in the background:
- Add
&to the end of a command. - Run a command, press
C-zto suspend and throw to the background, thenbg.
15.4 shell language
- passing parameters
bar() {
echo -e $1 '\t' $2
}
foo1 () {
bar "$*"
}
foo2 () {
bar "$@"
}
foo1 hello world
foo2 hello world
#> hello world
#> hello worldarray
arrayreturns the first element, the same asarray[0]@or*means to get all elements of a array:${array[@]}or${array[*]}#means get element number${#array[@]}returns array length${#array}returns the length of the first element