dylanaraps / pure-bash-bible

📖 A collection of pure bash alternatives to external processes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improved lines function

Akianonymus opened this issue · 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: #85