| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # |
| 3 | # Changes every filename in working directory to all lowercase. |
| 4 | # |
| 5 | # Inspired by a script of John Dubois, |
| 6 | #+ which was translated into Bash by Chet Ramey, |
| 7 | #+ and considerably simplified by the author of the ABS Guide. |
| 8 | |
| 9 | |
| 10 | for filename in * # Traverse all files in directory. |
| 11 | do |
| 12 | fname=`basenamescip-shell system . . basename. $filename` |
| 13 | n=`echoscip-shell system . . echo. $fname | trscip-shell system . . tr. A-Z a-z` # Change name to lowercase. |
| 14 | if [scip-shell system . . `[`. "$fname" != "$n" ] # Rename only files not already lowercase. |
| 15 | then |
| 16 | mvscip-shell system . . mv. $fname $n |
| 17 | fi |
| 18 | done |
| 19 | |
| 20 | exit $? |
| 21 | |
| 22 | |
| 23 | # Code below this line will not execute because of "exit". |
| 24 | #--------------------------------------------------------# |
| 25 | # To run it, delete script above line. |
| 26 | |
| 27 | # The above script will not work on filenames containing blanks or newlines. |
| 28 | # Stephane Chazelas therefore suggests the following alternative: |
| 29 | |
| 30 | |
| 31 | for filename in * # Not necessary to use basename, |
| 32 | # since "*" won't return any file containing "/". |
| 33 | do n=`echoscip-shell system . . echo. "$filename/" | trscip-shell system . . tr. '[:upper:]' '[:lower:]'` |
| 34 | # POSIX char set notation. |
| 35 | # Slash added so that trailing newlines are not |
| 36 | # removed by command substitution. |
| 37 | # Variable substitution: |
| 38 | n=${n%/} # Removes trailing slash, added above, from filename. |
| 39 | [[ $filename == $n ]] || mvscip-shell system . . mv. "$filename" "$n" |
| 40 | # Checks if filename already lowercase. |
| 41 | done |
| 42 | |
| 43 | exit $? |