0
我定義了一個函數t
,它只返回傳遞給它的第一個參數。在開始時似乎工作很好。但在午餐休息後,我記得t
,沒有通過任何論點。它在1日返回的代碼是127
,而不是我預期的0
。之後,它在我預計在最後一次召回時工作正常。bash中奇怪的返回碼行爲
這很奇怪。它會發生什麼?還是我做錯了什麼?
$ t; echo $? ## the 1st time I call function t, its returncode is 127
127
$ t 3; echo $?
3
$ t; echo $? ## the 2nd time I call function t, its returncode is 0
0
$ t; echo $? ## the 3rd time I call function t, its returncode is 0
0
$ declare -f t
t()
{
return $1
}
$
$ echo $SHELL
/bin/bash
$ bash --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
$ lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.11 (Final)
Release: 5.11
Codename: Final
總是引用變量,如果你不知道它們的值:'return「$ 1」'這會給你一個錯誤。 – ceving