4-return-value.sh 325 Bytes
Newer Older
Administrator's avatar
Administrator committed
1
#!/bin/sh
Administrator's avatar
Administrator committed
2
# Evaluating a function's return value.
3

Administrator's avatar
Administrator committed
4 5 6 7 8 9 10 11 12 13 14
# Filter with return value 0 if no match, 1 otherwise.
word_filter_2() {
    if grep -iv "$1" ; then
        return 0
    else
        return 1
    fi
}

echo "Hi, world." | word_filter_2 "hi" || echo "Invalid input for word_filter_2."

Administrator's avatar
Administrator committed
15
# @Test
16
# vim: ai et sts=4 ts=4 sw=4