locker
locker copied to clipboard
[Optimize] replace tr
FIRST
echo "$(tr ' ' '#' <<< "$dir_hash")"
can be replaced with
echo ${dir_hash// /#}
SECOND
echo "$(echo "$1" | tr '[:lower:]' '[:upper:]')"
can be replaced with
echo ${1^^}
THIRD
echo "$(echo "$1" | tr '[:upper:]' '[:lower:]')"
can be replaced with
echo ${1,,}
Could do this too
printf "[*] Passed OPERATION is: %s\n" "$(get_upper $OP)"
could just be changed to
printf "[*] Passed OPERATION is: %s\n" "${OP^^}"
And
OP=$(get_lower $1)
could be
OP=${1,,}
With these last 2 you can ditch the get_upper and get_lower functions
This is basically turning this into a even more bashism shell-script, thus removing even more the capacity to run this on any other shell.
Considering the shebang is #!/usr/bin/sh I'd ask to remain the way it is right now and remove the other two bashisms on the script.
From what I have tested these work totally fine with the sh shebang too
That sh shebang can be a symlink to any other shell, including dash/fish/ash/sh/..., on many systems that don't even have bash installed. Those variable substitutions will decrease further compatibility.
It is to the maintainer to decide if this script is meant only to run on bash, and if so, the shebang needs to be changed to #!/usr/bin/env bash.

@The-Repo-Club Based on what @BeyondMagic is saying, it won't be a good idea to move to not using truncate if we want to keep support for more than bash.