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

Bash 3.x compatibility #181

Merged
merged 5 commits into from
May 26, 2020
Merged

Bash 3.x compatibility #181

merged 5 commits into from
May 26, 2020

Conversation

bayandin
Copy link
Contributor

@bayandin bayandin commented May 1, 2020

Default bash installed on macOS is 3.2.57.
And there are some difference in brace expansion for @ for bash 3.x and 5.x:

$ /bin/bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19)
Copyright (C) 2007 Free Software Foundation, Inc.

$ /bin/bash -c 'set -u; echo "${@}OK"'
/bin/bash: @: unbound variable
$ /usr/local/bin/bash --version
GNU bash, version 5.0.17(1)-release (x86_64-apple-darwin19.4.0)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ /usr/local/bin/bash -c 'set -u; echo "${@}OK"'
OK

I suggest to replace ${@} with $@ to make tfenv 2 compatible with default bash on macOS:

$ /bin/bash -c 'set -u; echo "$@OK"'
OK

$ /usr/local/bin/bash -c 'set -u; echo "$@OK"'
OK

I ran shellcheck against my changes and it suggested to replace $@ to $* for printing logs, since it was mixing string variables and arrays (https://github.com/koalaman/shellcheck/wiki/SC2145).

All the tests have passed on bash 3.x locally on my mac.

My bash knowledge quite limited, so I'm not aware of the potential drawbacks for this solution.

Closes #180

@bayandin
Copy link
Contributor Author

bayandin commented May 1, 2020

There're some errors from tests on macOS:

./test/test_uninstall.sh: line 65: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
./test/test_uninstall.sh: line 66: 0.9.1: syntax error: invalid arithmetic operator (error token is ".9.1")
./test/test_uninstall.sh: line 67: 0.11.15-oci: syntax error: invalid arithmetic operator (error token is ".11.15-oci")
./test/test_uninstall.sh: line 68: latest: unbound variable

https://travis-ci.com/github/tfutils/tfenv/jobs/326295469

chenrui333
chenrui333 previously approved these changes May 1, 2020
@bayandin bayandin marked this pull request as draft May 1, 2020 13:29
@bayandin
Copy link
Contributor Author

bayandin commented May 7, 2020

It looks like all the tests are fine now on default macOS bash

@bayandin bayandin marked this pull request as ready for review May 7, 2020 07:51
@chenrui333
Copy link

chenrui333 commented May 9, 2020

@Mike Peachey @Zordrak can you take a look at this PR? Thanks!

@chenrui333
Copy link

ping @Zordrak

Copy link
Collaborator

@Zordrak Zordrak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate that this is necessary, but I appreciate the effort gone to in doing it.

@bayandin
Copy link
Contributor Author

Thanks @Zordrak!

@Zordrak Zordrak merged commit fccc154 into tfutils:master May 26, 2020
@bayandin bayandin deleted the bash-3.x-compatibility branch May 26, 2020 15:58
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

Successfully merging this pull request may close these issues.

Tried update cask formula to 2.0.0
3 participants