Skip to content

Latest commit

 

History

History
48 lines (30 loc) · 912 Bytes

in-list.md

File metadata and controls

48 lines (30 loc) · 912 Bytes

src/in-list.bash

Test if a value is in a list.

Overview

in-list tests if given string is found in a list.

Index

in-list

Test if given string is found in the remaining arguments.

Example

source "${BASH_SOURCE[0]%/*}/libs/biapy-bashlings/src/in-list.bash"
value='te(x|s)t'
example_list=( 'test' 'second text' 10 11 )
if in-list "${value}" ${example_list[@]+"${example_list[@]}"} then
  echo "Found."
else
  echo "Error: Not found." >&2
  exit 1
fi

Arguments

  • $1 (string): The searched string, allow for regex syntax (excluding ^ and $).
  • ... (any): The contents of the list in which the string is searched.

Exit codes

  • 0: If string is found in list.
  • 1: If string is not found in list, or string is missing.

Output on stderr

  • Display an error if string is missing.

See also