shell腳本集合及學習筆記

1.向指定類型的文件插入特定行

問題由來

/usr/bin/ld: /tmp/ccwmoa0L.o: in function `do_chrdev':
/home/hu/firmware-mod-kit/src/uncramfs/uncramfs.c:324: undefined reference to `minor'
/usr/bin/ld: /home/hu/firmware-mod-kit/src/uncramfs/uncramfs.c:324: undefined reference to `major'
/usr/bin/ld: /tmp/ccwmoa0L.o: in function `do_blkdev':
/home/hu/firmware-mod-kit/src/uncramfs/uncramfs.c:364: undefined reference to `minor'
/usr/bin/ld: /home/hu/firmware-mod-kit/src/uncramfs/uncramfs.c:364: undefined reference to `major'
collect2: error: ld returned 1 exit status
make[1]: *** [<builtin>: uncramfs] Error 1

需要向.c文件中加入
#include <sys/sysmacros.h>
編寫insert2file.sh

#!/bin/bash
i=0
pwd=""
function read_dir()
{


pwd=$1
for file in `ls $1`
do
	if [ -d $1"/"$file ]
	then
		read_dir $1"/"$file
		pwd=${pwd%/*}
	elif [[ "$file" == *.c ]]
	then
	sed -i '/#include/i\#include <sys\/sysmacros.h>' $pwd"/"$file
	fi
	done
}
read_dir $1

最後執行

./insert2file.sh ~/firmware-mod-kit/src

2.python2與python3切換

python2切換至python3
python2_3.sh

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python

python3切換至python2
python3_2.sh

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python2 /usr/bin/python

3.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章