相关疑难解决方法(0)

Bash函数中返回和退出之间的区别

BASH函数中的returnand exit语句与退出代码有什么区别?

bash return function return-value exit

399
推荐指数
8
解决办法
37万
查看次数

Git预推钩

我想在每次git推送之前运行一个单元测试,如果测试失败,取消推送,但我甚至找不到预推钩,只有pre-commit和pre-rebase.

git hook

103
推荐指数
6
解决办法
6万
查看次数

在Bash脚本中引发错误

我想在Bash脚本中引发错误,消息"Test cases Failed !!!".在Bash中如何做到这一点?

例如:

if [ condition ]; then
    raise error "Test cases failed !!!"
fi
Run Code Online (Sandbox Code Playgroud)

linux error-handling bash shell

84
推荐指数
5
解决办法
6万
查看次数

bash: `set -e` 在 if 表达式中使用时不起作用?

看看这个小脚本:

#!/bin/bash

function do_something() {(
    set -e

    mkdir "/opt/some_folder"                                     # <== returns 1 -> abort?
    echo "mkdir returned $?"                                     # <== sets $0 to 0 again

    rsync $( readlink -f "${BASH_SOURCE[0]}" ) /opt/some_folder/ # <== returns 23 -> abort?
    echo "rsync returned $?"                                     # <== sets $0 to 0 again
)}


# here  every command inside `do_something` will be executed - regardless of errors
echo "run do_something in if-context.."
if ! do_something ; then
  echo "running do_something did not work" …
Run Code Online (Sandbox Code Playgroud)

bash if-statement subshell

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