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

chore: Use command -v over which for portability #1658

Merged

Conversation

matthewfeickert
Copy link
Contributor

@matthewfeickert matthewfeickert commented Mar 21, 2022

command -v is a POSIX safe way to find an executable program. While which is very common, it still requires installation on many Linux operating systems, and so command -v can offer a more portable alternative with a very low amount of additional cognitive overhead on the maintainers.

Additionally, use a subshell, $(), over backticks for command substitution as $() is recommended for multiple reasons including readability.

c.f.:

I made the decision to leave which in

RUN yum install -y gcc-c++ rpm-build which git python-srpm-macros centos-release-scl vim

and

RUN dnf install -y gcc-c++ rpm-build which git python-srpm-macros vim dnf-plugins-core

while no longer required, as I figured that these serve as debugging environments where having which handy might be nice for alternative reasons, just as how vim is installed in them as well.

@matthewfeickert
Copy link
Contributor Author

@simonmichal This is ready for review. I didn't open an Issue to discuss this as it seems small enough/low enough change burden to not be controversial, but I can appreciate that this could also be viewed as stylistic and so not acceptable. If so, my apologies, and feel free to close. 👍

'command -v' is a POSIX safe way to find an executable program.
While 'which' is very common, it still requires installation on many
Linux operating systems, and so 'command -v' can offer a more portable
alternative with a very low amount of additional cognitive overhead on
the maintainers.

Additionally, use a subshell, $(), over backticks for command substitution
as $() is recommended for multiple reasons including readability.
c.f.:
* https://stackoverflow.com/a/4708569/8931942
* Why is $(...) preferred over `...` (backticks)?
   - http://mywiki.wooledge.org/BashFAQ/082
* POSIX spec for Command Substitution
   - https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html#tag_23_02_06_03
@simonmichal simonmichal merged commit 2ed76c1 into xrootd:master Mar 22, 2022
@matthewfeickert matthewfeickert deleted the feat/use-command-over-which branch March 22, 2022 15:06
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.

None yet

2 participants