pure-bash-bible icon indicating copy to clipboard operation
pure-bash-bible copied to clipboard

Improved lines function

Open Akianonymus opened this issue 4 years ago • 0 comments

lines function could be easily changed to read from variable, file ( as it does ) and a pipe output. Here is the code that works for me:

Usage: lines < "file" or lines <<< "$variable" or echo something | lines

lines() {
    mapfile -tn 0 lines
    printf '%s\n' "${#lines[@]}"
}

Similar issue that was closed: https://github.com/dylanaraps/pure-bash-bible/issues/85

Akianonymus avatar Apr 26 '20 14:04 Akianonymus