shell脚本集合及学习笔记

本文详细介绍了如何解决Linux环境下编译过程中遇到的未定义引用错误,通过向C源文件添加必要的头文件包含路径。此外,还提供了Python2与Python3版本间切换的实用脚本,帮助开发者轻松应对不同项目需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值