Add ability to source catmd.sh itself (providing catmd() also as function)
Outsourced line reading function to linefeeder
This commit is contained in:
32
linefeeder/linefeeder.sh
Executable file
32
linefeeder/linefeeder.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
# define parseline() in the sourcing script
|
||||
|
||||
linefeeder() {
|
||||
for arg in "$@"; do
|
||||
case "$1" in
|
||||
-)
|
||||
# treat - as input stream
|
||||
break;;
|
||||
-*)
|
||||
# Ignore options for now
|
||||
shift;;
|
||||
esac
|
||||
done
|
||||
|
||||
local file=
|
||||
local line=
|
||||
local args=("$@")
|
||||
|
||||
# Use standard input if no files are present
|
||||
[ $# -eq 0 ] && args[0]="/dev/stdin"
|
||||
|
||||
for file in "${args[@]}"; do
|
||||
[ "$file" == "-" ] && file="/dev/stdin"
|
||||
while IFS='' read -r line; do
|
||||
parseline "$line"
|
||||
done <"${file}"
|
||||
# If last line in a file has no newline, read ends but still populates $line
|
||||
[[ $line ]] && parseline "$line"
|
||||
done
|
||||
}
|
Reference in New Issue
Block a user