As I said in a comment of the OP, you can use (in Bash≥4) the following:
${var,,}
${var^}
to respectively have the expansion of var
in lowercase and var
in lowercase with first letter capitalize. The good news is that this also works on each field of an array.
Note. It is not clear from you question whether you need to apply this on each word of a line, or on each line. The following addresses the problem of each word of a line. Please refer to Steven Penny's answer to process only each line.
Here you go, in a much better style!
#!/bin/bash
file=names.txt
echo "#################################"
k=1
while read -r -a line_ary;do
lc_ary=( "${line_ary[@],,}" )
echo "Line # $k: ${lc_ary[@]^}"
((++k))
done < "$file"
echo "Total number of lines in file: $k"
First we read each line as an array line_ary
(each field is a word).
The part lc_ary=( "${line_ary[@],,}" )
converts each field of line_ary
to all lowercase and stores the resulting array into lc_ary
.
We now only need to apply ^
to the array lc_ary
and echo it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…