相关疑难解决方法(0)

在bash中有"goto"声明吗?

在bash中有"goto"声明吗?我知道这被认为是不好的做法,但我需要特别"goto".

linux bash shell goto

186
推荐指数
9
解决办法
34万
查看次数

如何在bash中退出函数

如果条件为真而没有终止整个脚本,你将如何退出函数,只需在调用函数之前返回.

# 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)

bash function exit

72
推荐指数
3
解决办法
8万
查看次数

使用`sh`和`source`有什么区别?

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)

unix linux bash shell

52
推荐指数
3
解决办法
3万
查看次数

在"陷阱退出"中获取shell脚本的exitcode

我想在我的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 吗?

[更新:]我不知道我之前测试过的是什么.这段代码就像一个魅力,所以我把它留在这里作为一个小而好的例子.

bash shell exit-code bash-trap

6
推荐指数
1
解决办法
4397
查看次数

标签 统计

bash ×4

shell ×3

linux ×2

bash-trap ×1

exit ×1

exit-code ×1

function ×1

goto ×1

unix ×1