一些shell命令
- for循环
1 | for file in `ls /etc` |
- if
1 | if condition |
- case
1 | case "$varname" in |
- 文件包含
1 | source ./function.sh |
- 字符串
1 | string="abcd" |
- 数组
1 | arr=(1 2 3 4 5) |
- 问号,和C里面的问号一样
1 | a=10 |
/dev/null是个空文件,清空一个文件可以用cat /dev/null > tmp.log,不想保存log,也不想输出到屏幕,可以1>/dev/null 2>&1- 清空一个文件也可用
: > tmp.log,:是个内建命令,什么也不做,永远返回0
1 | : |
cp t.{txt,back}文件名扩展- 大括号和小括号的区别
1 | a=123 |
sudo sh -c "...",引号里的内容都会有sudo权限echo $(( 2#101011 )),这里是2进制的意思trap1
2
3
4
5
6
7
8
9
10
11trap "echo Booh!" SIGINT SIGTERM
echo "it's going to run until you hit Ctrl+Z"
echo "hit Ctrl+C to be blown away!"
while true:
do
sleep 60
done
“kill pid” 会发送SIGTERM到进程pid.
在终端中敲入interrupt key(DELETE或ctrl+c)会产生SIGINT信号。
“kill -9 pid” 会发送SIGKILL到进程pid,SIGKILL不能被捕获,会直接结束