在bash中有"goto"声明吗?我知道这被认为是不好的做法,但我需要特别"goto".
如果条件为真而没有终止整个脚本,你将如何退出函数,只需在调用函数之前返回.
例
# Start script
Do scripty stuff here
Ok now lets call FUNCT
FUNCT
Here is A to come back to
function FUNCT {
if [ blah is false ]; then
exit the function and go up to A
else
keep running the function
fi
}
Run Code Online (Sandbox Code Playgroud) sh和之间有什么区别source?
source: source filename [arguments]
Read and execute commands from FILENAME and return. The pathnames
in $PATH are used to find the directory containing FILENAME. If any
ARGUMENTS are supplied, they become the positional parameters when
FILENAME is executed.
Run Code Online (Sandbox Code Playgroud)
并为man sh:
NAME
bash - GNU Bourne-Again SHell
SYNOPSIS
bash [options] [file]
COPYRIGHT
Bash is Copyright (C) 1989-2004 by the Free Software Foundation, Inc.
DESCRIPTION
Bash is an sh-compatible command language interpreter that executes commands read …Run Code Online (Sandbox Code Playgroud) 我想在我的Bash脚本中进行清理操作,如下所示:
#! /bin/bash
set -eu
trap 'echo "E: failed with exitcode $?" 1>&2' ERR
true
false
Run Code Online (Sandbox Code Playgroud)
使用$?脑海作为一种自然选择,但事实并非如此.它总是包含0.有什么方法可以"窥探" ERR陷阱中的exitcode 吗?
[更新:]我不知道我之前测试过的是什么.这段代码就像一个魅力,所以我把它留在这里作为一个小而好的例子.