zoukankan      html  css  js  c++  java
  • 基于cygwin构建u-boot(五)结尾:shell 工具

    结尾,基于cygwin对u-boot的处理,很大一部分都是再处理 路径等相关的问题,只有一个涉及到gcc的参数配置。

    为了达到顺利编译的目的,使用shell下的部分工具进行处理。

    1、sed

    sed简单说,是一种按照特定处理方式,对指定文件 逐行处理 的脚本程序。

     1 $ sed --help
     2 用法: sed [选项]... {脚本(如果没有其他脚本)} [输入文件]...
     3 
     4   -n, --quiet, --silent
     5                  取消自动打印模式空间
     6   -e 脚本, --expression=脚本
     7                  添加“脚本”到程序的运行列表
     8   -f 脚本文件, --file=脚本文件
     9                  添加“脚本文件”到程序的运行列表
    10   --follow-symlinks
    11                  直接修改文件时跟随软链接
    12   -i[SUFFIX], --in-place[=SUFFIX]
    13                  edit files in place (makes backup if SUFFIX supplied)
    14   -b, --binary
    15                  以二进制方式打开文件 (回车加换行不做特殊处理)
    16   -l N, --line-length=N
    17                  指定“l”命令的换行期望长度
    18   --posix
    19                  关闭所有 GNU 扩展
    20   -r, --regexp-extended
    21                  在脚本中使用扩展正则表达式
    22   -s, --separate
    23                  将输入文件视为各个独立的文件而不是一个长的连续输入
    24   -u, --unbuffered
    25                  从输入文件读取最少的数据,更频繁的刷新输出
    26   -z, --null-data
    27                  separate lines by NUL characters
    28       --help     打印帮助并退出
    29       --version  输出版本信息并退出
    30 
    31 如果没有 -e, --expression, -f 或 --file 选项,那么第一个非选项参数被视为
    32 sed脚本。其他非选项参数被视为输入文件,如果没有输入文件,那么程序将从标准
    33 输入读取数据。

    脚本中,替换功能为 '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

    1 $ help if
    2 if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi

    shell下提供 if then elif else 进行判断,可以解决 之前 .depend不存在时的处理,但还需要识别文件是否存在的功能,这就需要test函数。

    3、test

     1 $ help test
     2 test: test [expr]
     3     Evaluate conditional expression.
     4 
     5     Exits with a status of 0 (true) or 1 (false) depending on
     6     the evaluation of EXPR.  Expressions may be unary or binary.  Unary
     7     expressions are often used to examine the status of a file.  There
     8     are string operators as well, and numeric comparison operators.
     9 
    10     File operators:
    11 
    12       -a FILE        True if file exists.
    13       -b FILE        True if file is block special.
    14       -c FILE        True if file is character special.
    15       -d FILE        True if file is a directory.
    16       -e FILE        True if file exists.
    17       -f FILE        True if file exists and is a regular file.
    18       -g FILE        True if file is set-group-id.
    19       -h FILE        True if file is a symbolic link.
    20       -L FILE        True if file is a symbolic link.
    21       -k FILE        True if file has its `sticky' bit set.
    22       -p FILE        True if file is a named pipe.
    23       -r FILE        True if file is readable by you.
    24       -s FILE        True if file exists and is not empty.
    25       -S FILE        True if file is a socket.
    26       -t FD          True if FD is opened on a terminal.
    27       -u FILE        True if the file is set-user-id.
    28       -w FILE        True if the file is writable by you.
    29       -x FILE        True if the file is executable by you.
    30       -O FILE        True if the file is effectively owned by you.
    31       -G FILE        True if the file is effectively owned by your group.
    32       -N FILE        True if the file has been modified since it was last read.
    33 
    34       FILE1 -nt FILE2  True if file1 is newer than file2 (according to
    35                        modification date).
    36 
    37       FILE1 -ot FILE2  True if file1 is older than file2.
    38 
    39       FILE1 -ef FILE2  True if file1 is a hard link to file2.
    40 
    41     String operators:
    42 
    43       -z STRING      True if string is empty.
    44 
    45       -n STRING
    46          STRING      True if string is not empty.
    47 
    48       STRING1 = STRING2
    49                      True if the strings are equal.
    50       STRING1 != STRING2
    51                      True if the strings are not equal.
    52       STRING1 < STRING2
    53                      True if STRING1 sorts before STRING2 lexicographically.
    54       STRING1 > STRING2
    55                      True if STRING1 sorts after STRING2 lexicographically.
    56 
    57     Other operators:
    58 
    59       -o OPTION      True if the shell option OPTION is enabled.
    60       ! EXPR         True if expr is false.
    61       EXPR1 -a EXPR2 True if both expr1 AND expr2 are true.
    62       EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.
    63 
    64       arg1 OP arg2   Arithmetic tests.  OP is one of -eq, -ne,
    65                      -lt, -le, -gt, or -ge.
    66 
    67     Arithmetic binary operators return true if ARG1 is equal, not-equal,
    68     less-than, less-than-or-equal, greater-than, or greater-than-or-equal
    69     than ARG2.
    70 
    71     Exit Status:
    72     Returns success if EXPR evaluates to true; fails if EXPR evaluates to
    73     false or an invalid argument is given.

    其中 -e 或者 -f 参数用于判断文件是否存在。

    判断 .depend 是否存在的功能就是

     if test -e $@; then sed -i 's/d:///cygdrive/d//g' $@; fi

    更多精进的功能还需要更深入的熟悉linu shell。

  • 相关阅读:
    从壹开始前后端分离【 .NET Core2.2/3.0 +Vue2.0 】框架之十二 || 三种跨域方式比较,DTOs(数据传输对象)初探
    从壹开始前后端分离【 .NET Core2.0/3.0 +Vue2.0 】框架之十一 || AOP自定义筛选,Redis入门 11.1
    从壹开始前后端分离【 .NET Core2.0/3.0 +Vue2.0 】框架之十 || AOP面向切面编程浅解析:简单日志记录 + 服务切面缓存
    从壹开始前后端分离【 .NET Core2.2/3.0 +Vue2.0 】框架之九 || 依赖注入IoC学习 + AOP界面编程初探
    从壹开始前后端分离【 .NET Core2.2/3.0 +Vue2.0 】框架之七 || API项目整体搭建 6.2 轻量级ORM
    从壹开始前后端分离【 .NET Core2.2/3.0 +Vue2.0 】框架之六 || API项目整体搭建 6.1 仓储+服务+抽象接口模式
    从壹开始前后端分离【 .NET Core2.2/3.0 +Vue2.0 】框架之五 || Swagger的使用 3.3 JWT权限验证【必看】
    从壹开始前后端分离【 .NET Core2.0/3.0 +Vue2.0 】框架之四 || Swagger的使用 3.2
    从壹开始前后端分离【 .NET Core2.0/3.0 +Vue2.0 】框架之三 || Swagger的使用 3.1
    删除windows系统中以前的设备(比如以前的网卡)或驱动的方法
  • 原文地址:https://www.cnblogs.com/yvivid/p/3590659.html
Copyright © 2011-2022 走看看