d934e933cc8a6566b08d8d6753130843bc4865c4
4 # Desc: Consumes stdin; outputs as stdout lines
5 # Input: stdin (consumes)
6 # Output: stdout (newline delimited)
8 # return 1 stdin not present
9 # Example: printf "foo\nbar\n" | read_stdin
10 # Depends: GNU bash (version 5.1.16), GNU Coreutils 8.32 (cat)
12 # Attrib: Steven Baltakatei Sandoval (2024-01-29). reboil.com
13 local input_stdin output
;
16 if [[ -p /dev
/stdin
]]; then
17 input_stdin
="$(cat -)" ||
{
18 echo "FATAL:Error reading stdin." 1>&2; return 1; };
23 # Store as output array elements
25 if [[ -n $input_stdin ]]; then
26 while read -r line
; do
28 done < <(printf "%s\n" "$input_stdin") ||
{
29 echo "FATAL:Error parsing stdin."; return 1; };
33 printf "%s\n" "${output[@]}";
36 }; # read stdin to stdout lines
37 remove_leading_zeroes
() {
38 # Desc: Removes leading zeroes from lines
41 # Depends: BK-2020-03 read_stdin()
43 while read -r line
; do
44 printf "%s\n" "$line" |
sed -E -e 's/(^0*)([0-9].*)/\2/';
48 printf "00000.jpg\n0001.jpg\n2.jpg\n000003.jpg\n0010.jpg\n";
49 printf "========================\n";
50 printf "00000.jpg\n0001.jpg\n2.jpg\n000003.jpg\n0010.jpg\n" | remove_leading_zeroes
;