The are various ways:
(有多种方式:)
$ echo "$a" | tr '[:upper:]' '[:lower:]'
hi all
$ echo "$a" | awk '{print tolower($0)}'
hi all
Non-POSIX (非POSIX)
You may run into portability issues with the following examples:
(您可能会遇到以下示例的可移植性问题:)
$ echo "${a,,}"
hi all
$ echo "$a" | sed -e 's/(.*)/L1/'
hi all
# this also works:
$ sed -e 's/(.*)/L1/' <<< "$a"
hi all
$ echo "$a" | perl -ne 'print lc'
hi all
lc(){
case "$1" in
[A-Z])
n=$(printf "%d" "'$1")
n=$((n+32))
printf \$(printf "%o" "$n")
;;
*)
printf "%s" "$1"
;;
esac
}
word="I Love Bash"
for((i=0;i<${#word};i++))
do
ch="${word:$i:1}"
lc "$ch"
done
Note: YMMV on this one.
(注意:YMMV就此。)
Doesn't work for me (GNU bash version 4.2.46 and 4.0.33 (and same behaviour 2.05b.0 but nocasematch is not implemented)) even with using shopt -u nocasematch;
(即使使用shopt -u nocasematch;
它也对我不起作用(GNU bash版本4.2.46和4.0.33(具有相同的行为2.05b.0,但未实现nocasematch)) shopt -u nocasematch;
)
. (。)
Unsetting that nocasematch causes [[ "fooBaR" == "FOObar" ]] to match OK BUT inside case weirdly [bz] are incorrectly matched by [AZ]. (取消设置nocasematch会导致[[“” fooBaR“ ==” FOObar“]]奇怪地匹配[Bz]内的情况,但[AZ]错误地匹配了[Bz]。)
Bash is confused by the double-negative ("unsetting nocasematch")! (Bash被双负数(“ uncasematch”)弄糊涂了!)
:-) (:-))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…