/blog/images/avatar.webp

Hello World

Bash 调试技巧

Bash 调试技巧

bash 脚本是一种常用的脚本。当 bash 脚本执行出现错误的时候,我们可以通过调试的方式来定位问题所在。

Bash 调试常用选项

选项 说明
-v 打印执行命令
-x 类似 -v,并扩展了命令
-e 发生错误终止执行
-n 只检查语法,不执行脚本
-o pipefail 返回管道的错误状态

跟踪脚本的执行

输出调试信息

正常情况下,通过 bash test.sh./test.sh 执行脚本,利用 echo 或者 printf 命令可以输出一些信息,但是不能输出命令的具体执行情况。

Shell 配置文件的加载

Shell 启动方式

启动方式

Shell 的启动方式有以下四种:

  • 交互式登录
  • 非交互式登录
  • 交互式非登录
  • 非交互式非登录

其中交互式是指需要使用者手动输入的方式,而非交互式指的是脚本方式运行,不需要使用者手动输入。登录指的是使用者需要输入用户名和密码的方式,需要特定用户才能执行,而非登录不需要输入用户名和密码,任何用户都能执行。

Docker 使用 buildx 构建多平台镜像

Docker

apt-get install git

git 配置文件

git 配置文件有三个:

  1. /etc/gitconfig 是系统级配置文件,使用 git config --system 命令进行修改。
  2. ~/.gitconfig~/.config/git/config 是用户级配置文件,使用 git config --global 命令进行修改。
  3. local_dir/.git/config 是仓库级配置文件,使用 git config --local 命令进行修改。

设置用户信息

$ git config --global user.name "username"
$ git config --global user.email username@example.com

设置 git 默认编辑器

git config --global core.editor emacs

Astyle 配置使用

Astyle 工具下载


Astyle 参数详解

括号类型

default brace style

默认采用大括号样式,开口大括号不变,闭合大括号将与上一行断开。

–style=allman / –style=bsd / –style=break / -A1

int Foo(bool isBar)
{
    if (isBar)
    {
        bar();
        return 1;
    }
    else
        return 0;
}

–style=java / –style=attach / -A2

int Foo(bool isBar) {
    if (isBar) {
        bar();
        return 1;
    } else
        return 0;
}

–style=kr / –style=k&r / –style=k/r / -A3

int Foo(bool isBar)
{
    if (isBar) {
        bar();
        return 1;
    } else
        return 0;
}

–style=stroustrup / -A4

int Foo(bool isBar)
{
    if (isBar) {
        bar();
        return 1;
    }
    else
        return 0;
}

在 Keil 中的使用


C++11 标准容器使用

容器的定义

在数据存储上,有一种对象类型,它可以持有其它对象或指向其它对像的指针,这种对象类型就叫做容器。


容器的分类

  1. 顺序容器

顺序容器是一种各元素之间有顺序关系的线性表,是一种线性结构的有序集合。这种顺序不依赖于元素的值,而是与元素加入容器的顺序相对应。顺序容器提供控制元素存储和访问顺序的能力。

力扣737. 句子相似性 II

力扣737. Sentence Similarity II(句子相似性 II)

判断句子相似性(传递关系)。会员题。

示例 1:

../posts/01_学习/87_LeetCode/0737_句子相似性II/img/0737-1-description.png

输入:words1 = ["great","acting","skills"], words2 = ["fine","drama","talent"], pairs = [["great","good"],["fine","good"],["acting","drama"],["skills","talent"]]
输出:true
解释:...

提示:

力扣734. 句子相似性

力扣734. Sentence Similarity(句子相似性)

判断两个句子是否相似。会员题。

示例 1:

../posts/01_学习/87_LeetCode/0734_句子相似性/img/0734-1-description.png

输入:words1 = ["great","acting","skills"], words2 = ["fine","drama","talent"], pairs = [["great","fine"],["drama","acting"],["skills","talent"]]
输出:true
解释:...

提示:

力扣723. 粉碎糖果

力扣723. Candy Crush(粉碎糖果)

实现糖果粉碎游戏。会员题。

示例 1:

../posts/01_学习/87_LeetCode/0723_粉碎糖果/img/0723-1-description.png

输入:board = [[110,5,112,113,114],[210,211,5,213,214],[310,311,3,313,314],[410,411,412,5,414],[5,1,512,3,3],[610,4,1,613,614],[710,1,2,713,714],[810,1,2,1,1],[1,1,2,2,2],[4,1,4,4,1014]]
输出:[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[110,0,0,0,114],[210,0,0,0,214],[310,0,0,113,314],[410,0,0,213,414],[610,211,112,313,614],[710,311,412,613,714],[810,411,512,713,1014]]
解释:...

提示:

力扣716. 最大栈

力扣716. Max Stack(最大栈)

设计支持查找最大值的栈。会员题。

示例 1:

../posts/01_学习/87_LeetCode/0716_最大栈/img/0716-1-description.png

输入:["MaxStack","push","push","push","top","popMax","top","peekMax","pop","top"]
     [[],[5],[1],[5],[],[],[],[],[],[]]
输出:[null,null,null,null,5,5,1,5,1,5]
解释:...

提示: