bash/sh的退出码(EXIT STATUS)在0-255之间,EXIT STATUS The exit status of an executed command is the value returned by the waitpid system call or equivalent function. Exit statuses fall between 0 and The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described above in PARAMETERS. These assignment statements affect only the environment seen by that command. If the -k option is set (see the set builtin command below), then all parameter assignments are placed in the environment for a command, not just those that precede the command name. When bash invokes an external command, the variable _ is set to the full file name of the command and passed to that command in its environment.
谢谢,不过这种意思就是bash/sh没法返回256以外的数据之和吗?
#!/bin/bashsum() { echo $(($1 + $2)) }echo "input the first number:" read n1 echo "input the second number:" read n2res=$(sum $n1 $n2) echo "$n1 + $n2 = $res"
The exit status of an executed command is the value returned by the waitpid system call or equivalent function. Exit statuses fall between 0 and The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described above in
PARAMETERS. These assignment statements affect only the environment seen by that command. If the -k option is set (see the set builtin command below), then all parameter assignments are placed in the environment for a command, not just
those that precede the command name. When bash invokes an external command, the variable _ is set to the full file name of the command and passed to that command in its environment.
#!/bin/bashsum() {
echo $(($1 + $2))
}echo "input the first number:"
read n1
echo "input the second number:"
read n2res=$(sum $n1 $n2)
echo "$n1 + $n2 = $res"