bash从字符串中解析出带引号的变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
#shebang must be bash.
 
print_args()
{
	echo "1st is [$1]"
	echo "2nd is [$2]"
	echo "3rd is [$3]"
	echo "4th is [$4]"
	echo "5th is [$5]"
	echo "6th is [$6]"
	echo "7th is [$7]"
	echo "8th is [$8]"
}
 
VAR1=(1 2 "3 4" 5)
print_args "${VAR1[@]}"
 
VAR2="11 22 \"33 44\" 55"
#eval "VAR2=($VAR2)"
declare -a "VAR2=($(echo $VAR2 | tr '`$<>' '????'))"
print_args "${VAR2[@]}"

refer to:
https://superuser.com/questions/1066455/how-to-split-a-string-with-quotes-like-command-arguments-in-bash

linux命令备忘录

名词

1
2
3
4
5
pie: position-independent executable
pic: position-independent code
aslr: address space layout randomization
got: global offset table
vdso: virtual dynamic shared object

swap文件

1
2
3
4
dd if=/dev/zero of=./swap_file bs=1G count=8
mkswap ./swap_file
swapon ./swap_file
swapoff ./swap_file

objcopy

1
2
3
objcopy -I binary -O elf32-i386 -B i386 test.jpg test.o
objdump -s -b binary test.o
readelf -s test.o

静态链编stdc++

1
-Bstatic -lstdc++ -Bdynamic

工具

1
2
3
4
systemtap
inotify-tools
windres
reptyr

自启动

1
2
3
4
5
6
7
8
9
10
11
12
#/lib/systemd/system/mytask.service
#ln -s /lib/systemd/system/mytask.service /etc/systemd/system/multi-user.target.wants/mytask.service
[Unit]
Description=mytask
After=network.target
 
[Service]
Type=simple
ExecStart=mytask.sh
 
[Install]
WantedBy=multi-user.target

refer to:
http://blog.chinaunix.net/uid-28461677-id-5766451.html
https://blog.csdn.net/weixin_33842304/article/details/91443399
https://unix.stackexchange.com/questions/4034/how-can-i-disown-a-running-process-and-associate-it-to-a-new-screen-shell
https://blog.csdn.net/wuzhong8809/article/details/117450302

Bash读取某一行某一列

打印第11行:
sed -n "11, 1p" /tmp/tmp.txt
或者
awk 'NR == 11 {print}' /tmp/tmp.txt

打印第3列:
awk '{print $3;}' /tmp/tmp.txt

打印总行数:
awk 'END {print NR}' /tmp/tmp.txt