小编m4x*_*4xx的帖子

当按下 ctrl+c 时,仅中断当前函数,而不是整个 bash 脚本

我正在尝试编写一个脚本,其中如果有人按下CTRL+ C(键盘中断),那么它不应该退出整个脚本,而只是退出当前的执行函数。

谁能建议我在这里可以使用什么逻辑?这是相同的一些示例代码

#!/bin/bash

func1()
{
wget https://example.com/test1.txt
cat text1.txt |awk '{print $3}'|tr -d '.' > temp1.txt
}

func2()
{
cat temp1.txt|<stdin-to-some-tool> > temp2.txt
}

func3()
{
<some-tool> temp2.txt > temp3.txt
}
Run Code Online (Sandbox Code Playgroud)

同样,如果我们在此之前停止该函数,其他函数仍应执行。

linux bash command-line shell-script bash-scripting

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

bash ×1

bash-scripting ×1

command-line ×1

linux ×1

shell-script ×1