$> my_array=(one two three)
$> echo ${my_array}
one
#!/usr/bin/env bash | |
# MIT © Sindre Sorhus - sindresorhus.com | |
# git hook to run a command after `git pull` if a specified file was changed | |
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`. | |
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" | |
check_run() { | |
echo "$changed_files" | grep --quiet "$1" && eval "$2" |
# check if variable is array, returns 0 on success, 1 otherwise | |
# @param mixed | |
is_array() | |
{ #detect if arg is an array, returns 0 on sucess, 1 otherwise | |
[ -z "$1" ] && return 1 | |
if [ -n "$BASH" ]; then | |
declare -p ${1} 2> /dev/null | grep 'declare \-a' >/dev/null && return 0 | |
fi | |
return 1 |
A tiny (265 byte) utility to create state machine components using two pure functions.
The API is a single function that accepts 2 pure functions as arguments: