From 9540436a2c4267f711d6f174f2e75f1c36689f1c Mon Sep 17 00:00:00 2001 From: Devansh-567 Date: Mon, 6 Jul 2026 18:22:42 +0530 Subject: [PATCH] codegen: use command -v instead of fragile which + \$? pattern Signed-off-by: Devansh-567 --- codegen/compile_protos.sh | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/codegen/compile_protos.sh b/codegen/compile_protos.sh index 951463c2..8a0628f9 100755 --- a/codegen/compile_protos.sh +++ b/codegen/compile_protos.sh @@ -25,24 +25,17 @@ if [ "$#" -ne 1 ]; then fi BUILD_DIR="$1" -PROTOC="$(which protoc)" -if [ "$?" -ne 0 ]; then - echo "Could not find protoc" - exit 2 -fi + +command -v protoc >/dev/null 2>&1 || { echo "Could not find protoc"; exit 2; } +PROTOC="$(command -v protoc)" echo "Using $PROTOC" -GRPC_CPP_PLUGIN="$(which grpc_cpp_plugin)" -if [ "$?" -ne 0 ]; then - echo "Could not find CPP protoc plugin" - exit 2 -fi -GRPC_PY_PLUGIN="$(which grpc_python_plugin)" -if [ "$?" -ne 0 ]; then - echo "Could not find Python protoc plugin" - exit 2 -fi +command -v grpc_cpp_plugin >/dev/null 2>&1 || { echo "Could not find CPP protoc plugin"; exit 2; } +GRPC_CPP_PLUGIN="$(command -v grpc_cpp_plugin)" + +command -v grpc_python_plugin >/dev/null 2>&1 || { echo "Could not find Python protoc plugin"; exit 2; } +GRPC_PY_PLUGIN="$(command -v grpc_python_plugin)" set -e