#!/bin/sh
# capitalize first letter of all items in current directory:
ls -1 | awk '
## This script gets run once for each line of output from the "ls -1" command.
{
space = " " ## a space character
dquote = "\"" ## a double-quote character
backslash = "\\" ## a backslash character
## Each line of input ($0) is a new file name to convert:
old_name = $0
## Insert backslashes in front of any " characters inside the file name,
## so that they are preserved when we later invoke system() on it:
gsub(dquote, backslash dquote, old_name)
## Extract the first character of the file name:
first_char = substr(old_name,1,1)
## And the rest of the characters:
the_rest = substr(old_name,2)
## Don't try to rename unless the first character is a lowercase letter:
if (first_char ~ "[a-z]") {
## Assemble the new file name:
new_name = toupper(first_char) the_rest
## Issue a command to rename the file:
rename = "/bin/mv"
system(rename space dquote old_name dquote space dquote new_name dquote)
}
}'