Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 558 Bytes

SC2151.md

File metadata and controls

31 lines (21 loc) · 558 Bytes

Pattern: Use of return with multiple values

Issue: -

Description

In bash, return can only be used to signal success or failure (0 = success, 1-255 = failure).

To return textual or multiple values from a function, write them to stdout and capture them with command substitution instead.

Example of incorrect code:

somefunc() {
  return foo bar
}

Example of correct code:

somefunc() {
  echo foo
  echo bar
  return 0
}

Further Reading