基于cygwin构建u-boot(五)结尾:shell 工具
结尾,基于cygwin对u-boot的处理,很大一部分都是再处理 路径等相关的问题,只有一个涉及到gcc的参数配置。
为了达到顺利编译的目的,使用shell下的部分工具进行处理。
1、sed
sed简单说,是一种按照特定处理方式,对指定文件 逐行处理 的脚本程序。
$ sed --help
用法: sed [选项]... {脚本(如果没有其他脚本)} [输入文件]... -n, --quiet, --silent
取消自动打印模式空间
-e 脚本, --expression=脚本
添加“脚本”到程序的运行列表
-f 脚本文件, --file=脚本文件
添加“脚本文件”到程序的运行列表
--follow-symlinks
直接修改文件时跟随软链接
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-b, --binary
以二进制方式打开文件 (回车加换行不做特殊处理)
-l N, --line-length=N
指定“l”命令的换行期望长度
--posix
关闭所有 GNU 扩展
-r, --regexp-extended
在脚本中使用扩展正则表达式
-s, --separate
将输入文件视为各个独立的文件而不是一个长的连续输入
-u, --unbuffered
从输入文件读取最少的数据,更频繁的刷新输出
-z, --null-data
separate lines by NUL characters
--help 打印帮助并退出
--version 输出版本信息并退出 如果没有 -e, --expression, -f 或 --file 选项,那么第一个非选项参数被视为
sed脚本。其他非选项参数被视为输入文件,如果没有输入文件,那么程序将从标准
输入读取数据。
脚本中,替换功能为 's/string1/string2/g'
其中:
1、s开头表示字符串替换;
2、string1 被 string2 替换; 其中 string如果带特殊字符需要用 \ 开始转义(例如 / 需要写为 \/ )
3、结尾的g表示全局替换,不添加表示只替换首个。
下面说明 rules.mk中 sed -e 's/\(.*\)\.\w/\1.o/的含义
-e表示特性脚本, s表示 字符串替换,
string1 = \(.*\)\.\w , \( 和 \)表示引用,被后面的 \1引用。 \w表示任意word(单词)
string2 =\1.o
相当于 将文件名 和 文件名后缀分开,将后缀名替换为o, 例如 hello.c 替换为 hello.o。
2、if
$ help if
if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
shell下提供 if then elif else 进行判断,可以解决 之前 .depend不存在时的处理,但还需要识别文件是否存在的功能,这就需要test函数。
3、test
$ help test
test: test [expr]
Evaluate conditional expression. Exits with a status of (true) or (false) depending on
the evaluation of EXPR. Expressions may be unary or binary. Unary
expressions are often used to examine the status of a file. There
are string operators as well, and numeric comparison operators. File operators: -a FILE True if file exists.
-b FILE True if file is block special.
-c FILE True if file is character special.
-d FILE True if file is a directory.
-e FILE True if file exists.
-f FILE True if file exists and is a regular file.
-g FILE True if file is set-group-id.
-h FILE True if file is a symbolic link.
-L FILE True if file is a symbolic link.
-k FILE True if file has its `sticky' bit set.
-p FILE True if file is a named pipe.
-r FILE True if file is readable by you.
-s FILE True if file exists and is not empty.
-S FILE True if file is a socket.
-t FD True if FD is opened on a terminal.
-u FILE True if the file is set-user-id.
-w FILE True if the file is writable by you.
-x FILE True if the file is executable by you.
-O FILE True if the file is effectively owned by you.
-G FILE True if the file is effectively owned by your group.
-N FILE True if the file has been modified since it was last read. FILE1 -nt FILE2 True if file1 is newer than file2 (according to
modification date). FILE1 -ot FILE2 True if file1 is older than file2. FILE1 -ef FILE2 True if file1 is a hard link to file2. String operators: -z STRING True if string is empty. -n STRING
STRING True if string is not empty. STRING1 = STRING2
True if the strings are equal.
STRING1 != STRING2
True if the strings are not equal.
STRING1 < STRING2
True if STRING1 sorts before STRING2 lexicographically.
STRING1 > STRING2
True if STRING1 sorts after STRING2 lexicographically. Other operators: -o OPTION True if the shell option OPTION is enabled.
! EXPR True if expr is false.
EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
EXPR1 -o EXPR2 True if either expr1 OR expr2 is true. arg1 OP arg2 Arithmetic tests. OP is one of -eq, -ne,
-lt, -le, -gt, or -ge. Arithmetic binary operators return true if ARG1 is equal, not-equal,
less-than, less-than-or-equal, greater-than, or greater-than-or-equal
than ARG2. Exit Status:
Returns success if EXPR evaluates to true; fails if EXPR evaluates to
false or an invalid argument is given.
其中 -e 或者 -f 参数用于判断文件是否存在。
判断 .depend 是否存在的功能就是
if test -e $@; then sed -i 's/d:\//\/cygdrive\/d\//g' $@; fi
更多精进的功能还需要更深入的熟悉linu shell。
基于cygwin构建u-boot(五)结尾:shell 工具的更多相关文章
- 基于cygwin构建u-boot(一)环境搭建
从本文开始,更系统的描述基于cygwin构建u-boot. 之前<痛苦的版本对齐>系列,对于cygwin环境下Sourcery CodeBench,u-boot-1.1.6的构建有侧面的说 ...
- 基于cygwin构建u-boot(三)make错误忽视
接上文,修改gcc 的-std标准后,.depend文件处理仍然出现了错误: 五.错误:make中命令报错(sed找不到需要的文件) 错误告警如下: make -C examples/api all ...
- Shell 脚本(五) Shell 工具 及 企业面试题
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 十.Shell工具(重点) 1.cut cut 的工作就是“剪”,具体的说就是在文件中负责剪切数据用的. ...
- 基于cygwin构建u-boot(四)libgcc引用
接上文,config.mk文件修改后,即使没有.depend也可以正常处理了: 六.错误:gcclib引用错误 完成之前几篇的工作后,程序就可以一直执行了,直到最后生成u-boot, 出现如下错误告警 ...
- 基于cygwin构建u-boot(二)gcc的C语言标准版本号(-std=)
接上文,修改Makefile和config.mk中,.depend相关文件格式后继续编译. 四.tools文件夹的文件编译错误 错误告警如下[多行信息,请使用右侧滚动条查看]: gcc -Wall - ...
- Linux Shell系列教程之(五)Shell字符串
本文是Linux Shell系列教程的第(五)篇,更多shell教程请看:Linux Shell系列教程 字符串是Shell编程中最常用最有用的数据类型,今天,Linux大学网就为大家介绍一下在She ...
- eclipse环境下基于已构建struts2项目整合spring+hibernate
本文是基于已构建的struts2项目基础上整合 spring+hibernate,若读者还不熟悉struts2项目,请先阅读 eclipse环境下基于tomcat-7.0.82构建struts2项目 ...
- Springboot(一):使用Intellij中的Spring Initializr来快速构建Spring Boot工程
使用Intellij中的Spring Initializr来快速构建Spring Boot工程 New---Project 可以看到图所示的创建功能窗口.其中Initial Service Url指向 ...
- DevOps实践之一:基于Docker构建企业Jenkins CI平台
基于Docker构建企业Jenkins CI平台 一.什么是CI 持续集成(Continuous integration)是一种软件开发实践,每次集成都通过自动化的构建(包括编译,发布,自动化测试)来 ...
随机推荐
- Python一路走来 DAY15 Javascript
JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的处理. 一 如何编写 ...
- python修改txt文件内容
①以r模式打开文件并用readlines方法读入列表l中 ②修改相关行,直接用l[n]形式即可 ③关闭文件 ④以w方式打开文件,用writelines方法写入文件(覆盖文件内容) ⑤关闭文件 需要注意 ...
- Ubuntu 14.04 标题栏实时显示上下行网速、CPU及内存使用情况
首先当然是用wget下载indicator-sysmonitor,终端执行命令:wget -c https://launchpad.net/indicator-sysmonitor/trunk/4.0 ...
- Adt 配置注释模板
点击Window->Preferences->Java->Code Style->Code Templates,如下图所示: 选中,点击右侧的Edit进行编辑.
- 使用Volley StringRequest Get的方式进行发票查询操作
//进行发票查询 btnFpSelect.setOnClickListener(btnFpSelectClickListener); private OnClickListener btnFpSele ...
- android真机调试
android开发可以使用google那个自带的模拟器来调试,不过那个模拟器启动实在太慢,太耗时了,不过,如果我们有android手机的话,我们可以直接在手机上调试,这样的话,速度就很快: 具体步骤如 ...
- cf413E Maze 2D
E. Maze 2D time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- SQL语言的组成
在正式学习SQL语言之前,首先让我们对SQL语言有一个基本认识,介绍一下SQL语言的 组成: 1.一个SQL数据库是表(Table)的集合,它由一个或多个SQL模式定义. 2.一个SQL表由行集构成, ...
- 又一编辑神器-百度编辑器-Ueditor
(Lionden<hsdlionden@gmail.com> 转载说明) 前段时间发表过一篇关于“KindEditor在JSP中使用”的博文.这几天在沈阳东软进行JavaWeb方面的实习工 ...
- PYCHARM配置文件如何导入
请到此下载,如下: http://share.weiyun.com/c00040649e85c4ab1dbc47a0fe9a0a7a 或者:http://files.cnblogs.com/files ...