lowercase.sh

来自「Shall高级编程」· Shell 代码 · 共 44 行

SH
44
字号
#!/bin/bash##  Changes every filename in working directory to all lowercase.##  Inspired by a script of John Dubois,#+ which was translated into Bash by Chet Ramey,#+ and considerably simplified by the author of the ABS Guide.for filename in *                # Traverse all files in directory.do   fname=`basename $filename`   n=`echo $fname | tr A-Z a-z`  # Change name to lowercase.   if [ "$fname" != "$n" ]       # Rename only files not already lowercase.   then     mv $fname $n   fi  done   exit $?# Code below this line will not execute because of "exit".#--------------------------------------------------------## To run it, delete script above line.# The above script will not work on filenames containing blanks or newlines.# Stephane Chazelas therefore suggests the following alternative:for filename in *    # Not necessary to use basename,                     # since "*" won't return any file containing "/".do n=`echo "$filename/" | tr '[:upper:]' '[:lower:]'`#                             POSIX char set notation.#                    Slash added so that trailing newlines are not#                    removed by command substitution.   # Variable substitution:   n=${n%/}          # Removes trailing slash, added above, from filename.   [[ $filename == $n ]] || mv "$filename" "$n"                     # Checks if filename already lowercase.doneexit $?

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?