From 4f06f5b8fe5b9f04487c403031c87be7b8baf08b Mon Sep 17 00:00:00 2001 From: Jeevitha Kannan K S Date: Thu, 7 Nov 2024 13:04:56 +0530 Subject: [PATCH] Refactor scripts to use `command -v` instead of `which` (#20306) `which` is not a core package is some distributions. Included changes from #20309 Release Notes: - N/A --- script/bootstrap | 2 +- script/install.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/script/bootstrap b/script/bootstrap index 999a11749c..454daf46e2 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -11,7 +11,7 @@ else fi # Install sqlx-cli if needed -if [[ "$(sqlx --version)" != "sqlx-cli 0.7.2" ]]; then +if ! [[ "$(command -v sqlx)" && "$(sqlx --version)" == "sqlx-cli 0.7.2" ]]; then echo "sqlx-cli not found or not the required version, installing version 0.7.2..." cargo install sqlx-cli --version 0.7.2 fi diff --git a/script/install.sh b/script/install.sh index daeaec181f..3f2c690779 100755 --- a/script/install.sh +++ b/script/install.sh @@ -33,11 +33,11 @@ main() { ;; esac - if which curl >/dev/null 2>&1; then + if command -v curl >/dev/null 2>&1; then curl () { command curl -fL "$@" } - elif which wget >/dev/null 2>&1; then + elif command -v wget >/dev/null 2>&1; then curl () { wget -O- "$@" } @@ -48,7 +48,7 @@ main() { "$platform" "$@" - if [ "$(which "zed")" = "$HOME/.local/bin/zed" ]; then + if [ "$(command -v zed)" = "$HOME/.local/bin/zed" ]; then echo "Zed has been installed. Run with 'zed'" else echo "To run Zed from your terminal, you must add ~/.local/bin to your PATH"