Hidden features of Bash
Shell scripts are often used as glue, for automation and simple one-off tasks. What are some of your favorite "hidden" features of the Bash shell/scripting language?
See also:
insert preceding line's final parameter
alt-. the most useful key combination ever, try it and see, for some reason no one knows about this one.
press it again and again to select older last parameters.
great when you want to do something else to something you used just a moment ago.
If you want to keep a process running after you log out:
disown -h <pid>
is a useful bash built-in. Unlike nohup
, you can run disown
on an already-running process.
First, stop your job with control-Z, get the pid from ps
(or use echo $!
), use bg
to send it to the background, then use disown
with the -h flag.
Don't forget to background your job or it will be killed when you logout.
Almost everything listed under EXPANSION section in the manual
In particular, parameter expansion:
$ I=foobar
$ echo ${I/oo/aa} #replacement
faabar
$ echo ${I:1:2} #substring
oo
$ echo ${I%bar} #trailing substitution
foo
$ echo ${I#foo} #leading substitution
bar
链接地址: http://www.djcxy.com/p/42812.html
上一篇: Python调试技巧
下一篇: Bash的隐藏功能