dylanaraps / pure-bash-bible

📖 A collection of pure bash alternatives to external processes.
MIT License
36.41k stars 3.27k forks source link

Improved lines function #101

Open Akianonymus opened 4 years ago

Akianonymus commented 4 years ago

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