Skip to content

Commit 2569687

Browse files
committed
added lowercase_file.sh
1 parent 867d4b4 commit 2569687

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

bin/lowercase_file.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
# vim:ts=4:sts=4:sw=4:et
3+
#
4+
# Author: Hari Sekhon
5+
# Date: 2025-04-26 02:44:42 +0800 (Sat, 26 Apr 2025)
6+
#
7+
# https///github.com/HariSekhon/DevOps-Bash-tools
8+
#
9+
# License: see accompanying Hari Sekhon LICENSE file
10+
#
11+
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
12+
#
13+
# https://www.linkedin.com/in/HariSekhon
14+
#
15+
16+
set -euo pipefail
17+
[ -n "${DEBUG:-}" ] && set -x
18+
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19+
20+
# shellcheck disable=SC1090,SC1091
21+
. "$srcdir/lib/utils.sh"
22+
23+
# shellcheck disable=SC2034,SC2154
24+
usage_description="
25+
Renames a file to lowercase, using an intermediate file to work around case insensitive filesystems like on macOS
26+
"
27+
28+
# used by usage() in lib/utils.sh
29+
# shellcheck disable=SC2034
30+
usage_args="<file>"
31+
32+
help_usage "$@"
33+
34+
num_args 1 "$@"
35+
36+
filename="$1"
37+
38+
if ! [ -f "$filename" ]; then
39+
die "File not found: $filename"
40+
fi
41+
42+
filename_lowercase="$(tr '[:upper:]' '[:lower:]' <<< "$filename")"
43+
44+
tmpfile="$filename.lowercase.tmp"
45+
46+
mv -fv "$filename" "$tmpfile"
47+
48+
mv -fv "$tmpfile" "$filename_lowercase"

0 commit comments

Comments
 (0)