基于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)是一种软件开发实践,每次集成都通过自动化的构建(包括编译,发布,自动化测试)来 ...
随机推荐
- C程序设计语言练习题1-9
练习1-9 编写一个将输入复制到输出的程序,并将其中连续的多个空格用一个空格代替. 代码如下: #include <stdio.h> // 包含标准库的信息. int main() // ...
- hdu 2019
Problem Description 有n(n<=100)个整数,已经按照从小到大顺序排列好,现在另外给一个整数x,请将该数插入到序列中,并使新的序列仍然有序. Input 输入数据包含多 ...
- Selenium2Library+ride学习笔记
一.环境部署 1.安装python2.7编译环境.ride环境以及Selenium2Library环境,环境部署可参见前面几节. 2.启动RIDE编译环境,导入Selenium2Library库. ...
- 转:从BeagleBone谈AM335x硬件系统设计
链接:http://blog.chinaunix.net/uid-730738-id-3266690.html 作者:chenzhufly 从BeagleBone谈AM335x硬件系统设计 日期 ...
- shell编程技术之-基础知识
一.脚本结构 linux下shell的脚本,是将一系列命令序列写在一个文本文件,而这个文本文件时可执行的.相对命令行来说,开发效率提高.因此他的构架有2部分构成#!和命令序列.其中#!指明此脚本是用哪 ...
- FJ省队集训DAY4 T3
#include<cstdio> #include<iostream> #include<cmath> #include<cstring> #inclu ...
- vim 中Ctags的安装和使用
Ctags是一个用来为源文件中的标识符(如变量.函数.类成员.宏定义等)创建索引文件的程序.这些tags文件能被编辑器或其它工具用来快速查找定位源代码中的符号(tag/symbol),如变量名,函数名 ...
- C#实现目录复制
摘自:http://www.cnblogs.com/zxjay/archive/2008/10/29/1322517.html FCL提供了文件移动.文件复制.目录移动的方法,但没提供目录复制的 ...
- 自制USB wifi信号放大天线
这是我的usb wifi天线第一个版本,灵感来自: http://www.instructables.com/id/EQARE4I72GEPUCHTHU/ http://www.usbwifi.orc ...
- java遍历Hashmap/Hashtable的几种方法
一>java遍历Hashtabe: import java.util.Hashtable; import java.util.Set; public class HashTableTest { ...