AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-505362

jian's questions

Martin Hope
jian
Asked: 2024-01-06 10:19:55 +0800 CST

bash 声明时带有额外的逗号

  • 5

Bash 中的“声明”是什么?

declare -r is_debug true
if [ "$is_debug" = true ]; then
    printf "%s\n", "is debug"
else
    printf "%s\n", "is not debug"
fi

declare -p is_debug
echo "${is_debug-isunset}"

输出:

jian@jian:~/Desktop/pg_src/src4/postgres$ bash /home/jian/scratch/scratchpads/47a6066b9dfaca1c2b13ea2e99f4e929/scratch.sh
is not debug
,declare -r is_debug
isunset
jian@jian:~/Desktop/pg_src/src4/postgres$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.


declare -p is_debug
echo "${is_debug-isunset}"

我对输出感到困惑,declare -r is_debug。我希望它能回来declare -r is_debug。

bash
  • 1 个回答
  • 41 Views
Martin Hope
jian
Asked: 2023-08-25 12:24:39 +0800 CST

gdb打印出指针是否为空

  • 5

来源:https://git.postgresql.org/cgit/postgresql.git/tree/src/backend/optimizer/plan/planner.c

(gdb) n
3556            if (root->group_pathkeys)
(gdb) s
3558            else if (root->window_pathkeys)
(gdb) print root->group_pathkeys==NULL
No symbol "NULL" in current context.
(gdb) s
3559                    root->query_pathkeys = root->window_pathkeys;
(gdb) s
query_planner (root=root@entry=0x55ffb53fdb70, qp_callback=qp_callback@entry=0x55ffb3299ee0 <standard_qp_callback>, qp_extra=qp_extra@entry=0x7ffc5db45260) at ../../Desktop/pg_sources/main/postgres/src/backend/optimizer/plan/planmain.c:219
219             fix_placeholder_input_needed_levels(root);

根据上面的内容,我可以猜测root->group_pathkeys == NULL并且root->query_pathkeys != NULL
可以使用 print 来评估表达式。类似于print (root->group_pathkeys==NULL)然后返回 1。

c
  • 1 个回答
  • 29 Views
Martin Hope
jian
Asked: 2023-08-20 16:04:55 +0800 CST

gdb 执行到特定函数

  • 5

https://git.postgresql.org/cgit/postgresql.git/tree/src/test/modules/delay_execution/delay_execution.c
https://stackoverflow.com/questions/11967440/stepping-into-specific-function-in -gdb

我加载了延迟执行模块。
然后gdb -p $proc
对 gdb 还很陌生。我可以让gdb直接执行到delay_execution_planner的开头吗?步骤很多,一步步按好像不太好。

gdb
  • 1 个回答
  • 13 Views
Martin Hope
jian
Asked: 2023-08-13 14:51:03 +0800 CST

在这种情况下什么是“读”?

  • 5

考虑到:

  • https://linuxcommand.org/lc3_man_pages/readh.html
  • https://man7.org/linux/man-pages/man2/read.2.html
  • https://git.savannah.gnu.org/cgit/coreutils.git/tree/src
  • https://stackoverflow.com/a/60869467/15603477
cat filename | while read i
do
    echo $i
done

所有其他答案都失败了,这个有效!这会将文本文件逐行剪切。
我想了解更多关于阅读的关键部分。但我找不到源代码。 which read无输出。在这种情况下什么是“读”?

bash
  • 2 个回答
  • 49 Views
Martin Hope
jian
Asked: 2023-07-07 21:53:53 +0800 CST

创建新的 git 分支时自动化

  • 5

https://wiki.postgresql.org/wiki/Working_with_Git#Using_git_hooks
我想快速测试我的想法(快速失败)。
所以无论我改变什么,都致力于当地分支机构。然后我使用切换到一个新分支

git checkout -b test1

我可以快速获取本地最新版本和远程版本(主分支),然后进行新的更改。

如何使用 git hooks 自动执行此操作。


https://postgresql.life/post/andrey_borodin/

我认为我所做的是一种反模式。我在 $HOME 目录下有 postgres0、postgres1、postgres2…postgresE、postgresF、postgres10…每当我不明白我在 postgresX 中更改的内容时 - 我会执行 git clone https://github.com/postgres/postgres postgresX+ 1。

是的,我知道 git 的发明是有原因的。但要给分支命名,我至少需要对更改的目的有一个微妙的了解。

基本上,当我创建新分支时,我可以自动获取最新的遥控器。但是在我切换之前如果旧分支没有提交,旧分支会丢失吗?(所以我需要防止这种情况发生)。


我想确保每次使用“git checkout -b”时,新分支的本地内容与最新的远程内容一样新鲜。(这意味着稍后当我进行一些更改或破坏某些内容时,这都是我的错)而且,前一个分支的更改仍然存在。(我想自动化这个)。

git
  • 1 个回答
  • 49 Views
Martin Hope
jian
Asked: 2023-07-04 20:06:20 +0800 CST

从 bash 历史记录中选择命令之前进行确认

  • 5

当我在终端中时,我可以使用向上箭头键获取历史命令(例如,bash build.sh),然后按 Enter,bash 命令立即运行,所以我想在终端上进行确认。

我可以将它粘贴到每个 sh 文件中,但最好将其停止在 bash 终端级别

bash
  • 1 个回答
  • 51 Views
Martin Hope
jian
Asked: 2023-06-28 15:34:03 +0800 CST

根据模式注释掉文件中的行

  • 5

文件:/home/jian/Desktop/pg_sources/main/postgres/src/test/regress/sql/test_setup.sql

246: --
247: -- Create some C functions that will be used by various tests.
248: --
249: 
250: CREATE FUNCTION binary_coercible(oid, oid)
251:     RETURNS bool
252:     AS :'regresslib', 'binary_coercible'
253:     LANGUAGE C STRICT STABLE PARALLEL SAFE;
254: 
255: CREATE FUNCTION ttdummy ()
256:     RETURNS trigger
257:     AS :'regresslib'
258:     LANGUAGE C;
259: 
260: CREATE FUNCTION get_columns_length(oid[])
261:     RETURNS int
262:     AS :'regresslib'
263:     LANGUAGE C STRICT STABLE PARALLEL SAFE;

我认为这些内容永远不会改变。

目前我正在使用

sed -i '250,263 s/^/--/' /home/jian/Desktop/pg_sources/main/postgres/src/test/regress/sql/test_setup.sql

注释掉 ss 函数,但这不安全,新行可以轻松添加在前面。
所以我试图找到一种方法来注释掉这些行。

模式将是:
注释掉以模式“C 函数”
开头的行逐行循环,以最后一行结束,具有模式“LANGUAGE C”

text-processing
  • 3 个回答
  • 50 Views
Martin Hope
jian
Asked: 2022-11-17 07:54:10 +0800 CST

HAVE_UNISTD_H 宏定义在哪里?

  • 5
#ifdef HAVE_UNISTD_H
#include<unistd.h>
#else
extern int getpid(void)
#endif /* HAVE_UNISTD_H */

我想这个想法是检查头文件<unistd.h>是否可用。如果没有,那么extern int getpid(void)
我知道这是非常基本的。但是我没有通过互联网找到好的结果。HAVE_UNISTD_H 宏是什么意思?

c
  • 1 个回答
  • 18 Views
Martin Hope
jian
Asked: 2022-11-09 09:57:20 +0800 CST

递归对目录及其子目录中的所有文件执行操作

  • 7

基于这个答案,我想对目录及其子目录中的所有文件执行操作。

以下命令适用于单个文件,也适用于循环中的多个文件。

for i in *.html; \
do sed -i '/<head>/a <link rel="stylesheet" href="/home/jian/postgres/doc/src/sgml/html/stylesheet.css">\' $i; \
done

但是以下命令将不起作用。

find . -type d -exec \
    for i in *.html; \
    do sed -i '/<head>/a <link rel="stylesheet" href="/home/jian/postgres/doc/src/sgml/html/stylesheet.css">\' $i; \
    done \
 \;

它给出了以下错误:

bash: syntax error near unexpected token `do'
bash: syntax error near unexpected token `done'
;: command not found

我在这里找到了一个相关的帖子。

bash
  • 1 个回答
  • 47 Views
Martin Hope
jian
Asked: 2022-07-13 07:22:24 +0800 CST

使测试功能可用或不返回错误

  • 0

使 -v 返回:

GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

在一个目录下,一个文件:makefile

ifneq ($(jobserver),T)
$(error This makefile only works with a Make program that supports $$(eval))
endif

按 make 类型调用 make

makefile:2: *** This makefile only works with a Make program that supports $(eval).  Stop.

即使我尝试

ifneq ($(eval),T)
$(error This makefile only works with a Make program that supports $$(eval))
endif

仍然返回

makefile:2: *** This makefile only works with a Make program that supports $(eval).  Stop.

我按照在线教程进行操作,这些 makefile 测试 make 中的功能/功能是否可用。它不应该产生错误。

make
  • 1 个回答
  • 14 Views
Martin Hope
jian
Asked: 2022-07-08 07:38:45 +0800 CST

gcc 版本 9 中 libm.a 的完整路径

  • 0

基于此:https :
//stackoverflow.com/questions/5925678/location-of-c-standard-library gcc --print-file-name=libm.a
返回:
/usr/lib/gcc/x86_64-linux- gnu/9/../../../x86_64-linux-gnu/libm.a


但是我找不到它。在当前目录(/usr/lib/gcc/x86_64-linux-gnu/9):我执行ls命令,返回以下内容:

cc1          crtfastmath.o      finclude           libcaf_single.a  libgfortran.spec  liblsan.so              libobjc_gc.so       libsupc++.a
cc1plus      crtoffloadbegin.o  include            libcc1.so        libgomp.a         liblsan_preinit.o       libquadmath.a       libtsan.a
collect2     crtoffloadend.o    libasan.a          libgcc.a         libgomp.so        liblto_plugin.so        libquadmath.so      libtsan.so
crtbegin.o   crtoffloadtable.o  libasan.so         libgcc_eh.a      libgomp.spec      liblto_plugin.so.0      libsanitizer.spec   libubsan.a
crtbeginS.o  crtprec32.o        libasan_preinit.o  libgcc_s.so      libitm.a          liblto_plugin.so.0.0.0  libssp_nonshared.a  libubsan.so
crtbeginT.o  crtprec64.o        libatomic.a        libgcov.a        libitm.so         libobjc.a               libstdc++.a         lto-wrapper
crtend.o     crtprec80.o        libatomic.so       libgfortran.a    libitm.spec       libobjc.so              libstdc++.so        lto1
crtendS.o    f951               libbacktrace.a     libgfortran.so   liblsan.a         libobjc_gc.a            libstdc++fs.a       plugin

只有finclude、include、plugin是目录。我已经检查过 libm.a 不存在。

为什么要打扰,因为基于此链接。(https://www.linuxtopia.org/online_books/an_introduction_to_gcc/gccintro_17.html)如果我找到正确的 libm.a 完整路径,我应该能够执行以下命令。

gcc -Wall calc.c /usr/lib/libm.a -o calc

但是以下命令仍然有效。

gcc -Wall calc.c -lm -o calc
gcc
  • 1 个回答
  • 64 Views
Martin Hope
jian
Asked: 2022-07-07 04:06:48 +0800 CST

./ 在 shell 中是什么意思?

  • -1

我有一个来自这里hello_world.c的简单文件。我想出了如何去做。

gcc -Wall -g hello_world.c -o hello 正在工作,但是如果我运行bash hello,则会出现错误:hello: hello: cannot execute binary file

sh hello然后错误:hello: 1: Syntax error: "(" unexpected
./hello打印出预期的行。

我以为这三个都是一样的。从结果来看不是。为什么其他两个不起作用?除了./hello,还有其他方法可以调用该文件hello吗?

bash path
  • 2 个回答
  • 79 Views
Martin Hope
jian
Asked: 2022-02-03 08:33:59 +0800 CST

使用 ripgrep 查找相邻单词

  • 1

如何使用 ripgrep 查找相邻的重复单词。例如

one hello hello world

如何hello hello使用 ripgrep 定位?

解决了

rg  '(hello)[[:blank:]]+\1' --pcre2  <<<'one hello hello world'
grep ripgrep
  • 2 个回答
  • 276 Views
Martin Hope
jian
Asked: 2022-01-15 03:11:30 +0800 CST

awk 从字符串中提取数字

  • 0

有多个相关的问题,似乎它们不能awk用来解决问题。

  • 从字符串中提取正/负浮点数
  • 如何从文件名中提取数字
echo "blah foo123bar234blah" | egrep -o '([0-9]+)' 

返回

123
234 

但

echo "blah foo123bar234blah" | 
    awk '{ match($0,/([0-9]+)/,m); print m[0], m[1],m[2]}'    

返回123 123和

echo "blah foo123bar234blah" | 
    awk '{ match($0,/([0-9]+).+([0-9]+)/,m); print m[0], m[1],m[2]}'    

返回 123bar234 123 4

在手册中的部分:match(string, regexp [, array])中,示例为:

echo foooobazbarrrrr |
    gawk '{ match($0, /(fo+).+(bar*)/, arr); print arr[1], arr[2]}'

哪个返回foooo barrrrr。

那么如何使用 awk(相当于grep -o)从字符串中提取多个数字?

awk
  • 7 个回答
  • 2333 Views
Martin Hope
jian
Asked: 2022-01-14 22:56:34 +0800 CST

如何使用 awk 在文件中间添加一行文本?

  • 3

这是一个很好的答案。 https://stackoverflow.com/a/6739327/15603477 但我还是有点困惑。

没有a变量,awk '/^nameserver/ { printf("nameserver 127.0.0.1\n")} {print}' file2将得到:

# Generated by NetworkManager
domain dhcp.example.com
search dhcp.example.com
nameserver 127.0.0.1
nameserver 10.0.0.1
nameserver 127.0.0.1
nameserver 10.0.0.2
nameserver 127.0.0.1
nameserver 10.0.0.3

在尝试了薮猫组合后,我发现我必须使用 awk '/^nameserver/ && !a { printf("nameserver 127.0.0.1\n"); a=1 } {print}' file2

但我仍然对阻止重复!a的功能感到困惑。a=1printf("nameserver 127.0.0.1\n")

awk
  • 2 个回答
  • 311 Views
Martin Hope
jian
Asked: 2022-01-14 21:27:28 +0800 CST

如何仅使用 awk 查找/替换和增加匹配的数字?

  • 0

https://stackoverflow.com/a/14348899/15603477
我确实理解以下答案。 sed -r 's/(.*)(\?cache_version=)([0-9]+)(.*)/echo "\1\2$((\3+1))\4"/ge' file
但我想知道如何在awk中做到这一点。
转换barbaz?cache_version=3fooooo为文件内容barbaz?cache_version=4fooooo
为test1

ello
barbaz?cache_version=3fooooo
bye

条件是找到行包含cache_version=然后将匹配行中的数值加1。
我什至找不到匹配的数值,更不用说增加数值了。

到目前为止,我只通过
awk '{if(/cache_version=([[:digit:]+])/) print $1}' < test1

awk
  • 2 个回答
  • 603 Views
Martin Hope
jian
Asked: 2022-01-13 21:29:25 +0800 CST

使用 awk 打印带有输出行的行号

  • 0

上下文:grep 用于文件中不同行的多个字符串(即整个文件,而不是基于行的搜索)?

egrep -nH 'Dansk|Norsk|Svenska' file3

或使用ripgrep

rg  'Dansk|Norsk|Svenska' file3

但有一个答案

awk '/Dansk/{a=1}/Norsk/{b=1}/Svenska/{c=1}END{ if (a && b && c) print $0 }'  file3

我不明白这个答案。

我明白了awk '/Dansk/{a=1}/Norsk/{b=1}/Svenska/{c=1}。

我认为现在的问题是使用 awk,在模式匹配时,使用输出行打印行号。

更新:我什至理解这个答案。更新:
几乎接近:

awk '/Dansk/{a=1}/Norsk/{b=1}/Svenska/{c=1}{ if (a || b || c ) print $0; next}1'  file3

它返回

Subtitle: 04, Language: da - Dansk, Content: Undefined, Stream id: 0x23,
        Subtitle: 05, Language: de - Deutsch, Content: Undefined, Stream id: 0x24,

预期回报是

   Subtitle: 04, Language: da - Dansk, Content: Undefined, Stream id: 0x23,

file3内容:

Disc Title: unknown
Title: 01, Length: 01:33:37.000 Chapters: 33, Cells: 31, Audio streams: 04, Subpictures: 20
        Subtitle: 01, Language: ar - Arabic, Content: Undefined, Stream id: 0x20, 
        Subtitle: 02, Language: bg - Bulgarian, Content: Undefined, Stream id: 0x21, 
        Subtitle: 03, Language: cs - Czech, Content: Undefined, Stream id: 0x22, 
        Subtitle: 04, Language: da - Dansk, Content: Undefined, Stream id: 0x23, 
        Subtitle: 05, Language: de - Deutsch, Content: Undefined, Stream id: 0x24, 
(...)

更新。几乎接近。
awk '/Dansk/{a=1}/Norsk/{b=1}/Svenska/{c=1}{ if (a || b || c ) print NR, $0}' file3 但它返回

6         Subtitle: 04, Language: da - Dansk, Content: Undefined, Stream id: 0x23,
7         Subtitle: 05, Language: de - Deutsch, Content: Undefined, Stream id: 0x24,
8 (...)
awk
  • 1 个回答
  • 680 Views
Martin Hope
jian
Asked: 2022-01-11 09:48:24 +0800 CST

按列排序未按预期工作

  • 0

cat marks.txt返回

1)  Amit    Physics  80
2)  Rahul   Maths    90
3)  Shyam   Biology  87
4)  Kedar   English  85
5)  Hari    History  89

awk -F" " '{ print $4"\t" $0 }' marks.txt | sort | cut -f 2-根据第四列成功对文本进行排序。

上下文:https
://stackoverflow.com/questions/17048188/how-to-use-awk-sort-by-column-3 但要模拟投票最高的答案: sort -t" " -nk4 marks.txt 但只返回:

1)  Amit    Physics  80
2)  Rahul   Maths    90
3)  Shyam   Biology  87
4)  Kedar   English  85
5)  Hari    History  89

为什么排序子句不起作用?

awk sort
  • 2 个回答
  • 151 Views
Martin Hope
jian
Asked: 2022-01-10 20:52:55 +0800 CST

awk NR%2{}1 含义

  • 3

我试图理解这段代码:

awk 'NR%2{printf "%s ",$0;next;}1' yourFile

现在我尝试自定义它。

鉴于此 error.txt 内容:

KEY 4048:1736 string
3
KEY 0:1772 string
1
KEY 4192:1349 string
1
KEY 7329:2407 string
2
KEY 0:1774 string
1

然后:

awk 'NR%2{printf NR "%s ", $0; next}1' error.txt

... 将返回:

1KEY 4048:1736 string 3
3KEY 0:1772 string 1
5KEY 4192:1349 string 1
7KEY 7329:2407 string 2
9KEY 0:1774 string 1

我想NR%2是指偶数行号,但我不确定1指的是什么。
没有1, awk 'NR%2{printf NR "%s ", $0; next}' error.txt 将返回一行。

1KEY 4048:1736 string 3KEY 0:1772 string 5KEY 4192:1349 string 7KEY 7329:2407 string 9KEY 0:1774 string 

总的来说,我仍然没有得到它。

到目前为止,我已经查看了这些页面:

  • https://www.tecmint.com/use-next-command-with-awk-in-linux/
  • https://stackoverflow.com/a/32482224/15603477
  • https://stackoverflow.com/a/9605559/15603477
awk
  • 2 个回答
  • 1026 Views
Martin Hope
jian
Asked: 2022-01-10 08:09:23 +0800 CST

在匹配的 sed 之后仅显示下一行

  • 2

https://stackoverflow.com/a/7451478/15603477

我明白grep -A1 'blah' logfile | grep -v "blah"

但我不明白sed -n '/blah/{n;p;}' logfile
到目前为止,我检查了手动 sed 命令行选项页面: https ://www.gnu.org/software/sed/manual/html_node/Command_002dLine-Options.html 。只有-n安静的意思。显然/blah/是指模式/blah/然后难以理解的部分是{n;p;}

sed
  • 1 个回答
  • 265 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve