Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Optimize] replace tr #1

Open
HeCodes2Much opened this issue Jan 9, 2022 · 4 comments
Open

[Optimize] replace tr #1

HeCodes2Much opened this issue Jan 9, 2022 · 4 comments

Comments

@HeCodes2Much
Copy link

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

@BeyondMagic
Copy link
Contributor

BeyondMagic commented Jan 9, 2022

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.

@HeCodes2Much
Copy link
Author

From what I have tested these work totally fine with the sh shebang too

@BeyondMagic
Copy link
Contributor

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.

image

@deepjyoti30
Copy link
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants