This is an automated email from the ASF dual-hosted git repository.

jojochuang pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 4999ac9ea27 HADOOP-19758. Avoid tput in shell usage formatting when 
unavailable. (#8387)
4999ac9ea27 is described below

commit 4999ac9ea27d1881cac95aa8636250f1c9b1d547
Author: Deepak Jain <[email protected]>
AuthorDate: Thu Jul 9 11:35:11 2026 -0400

    HADOOP-19758. Avoid tput in shell usage formatting when unavailable. (#8387)
---
 .../hadoop-common/src/main/bin/hadoop-functions.sh  |  8 +++++---
 .../src/test/scripts/hadoop_subcommands.bats        | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git 
a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh 
b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh
index a7acd69bf7b..bb36f913019 100755
--- a/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh
+++ b/hadoop-common-project/hadoop-common/src/main/bin/hadoop-functions.sh
@@ -375,9 +375,11 @@ function hadoop_generic_columnprinter
 
   if [[ -n "${COLUMNS}" ]]; then
     numcols=${COLUMNS}
-  else
-    numcols=$(tput cols) 2>/dev/null
-    COLUMNS=${numcols}
+  elif command -v tput >/dev/null 2>&1; then
+    numcols=$(tput cols 2>/dev/null)
+    if [[ "${numcols}" =~ ^[0-9]+$ ]]; then
+      COLUMNS=${numcols}
+    fi
   fi
 
   if [[ -z "${numcols}"
diff --git 
a/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommands.bats 
b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommands.bats
index c004a30d999..c790016523e 100755
--- 
a/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommands.bats
+++ 
b/hadoop-common-project/hadoop-common/src/test/scripts/hadoop_subcommands.bats
@@ -76,3 +76,24 @@ TOKEN
   run "${BATS_TEST_DIRNAME}/../../main/bin/hadoop" multi 1 2
   [ "${output}" = 2 ]
 }
+
+@test "hadoop_generic_columnprinter (missing tput)" {
+  local oldpath="${PATH}"
+  local fakebin="${TMP}/fakebin"
+
+  mkdir -p "${fakebin}"
+  ln -s "$(command -v sort)" "${fakebin}/sort"
+  ln -s "$(command -v fold)" "${fakebin}/fold"
+
+  PATH="${fakebin}"
+  unset COLUMNS
+
+  run hadoop_generic_columnprinter "" \
+    "archive-logs@client@combine aggregated logs into hadoop archives"
+
+  PATH="${oldpath}"
+
+  [ "${status}" -eq 0 ]
+  [[ "${output}" == *"archive-logs"* ]]
+  [[ "${output}" != *"tput: command not found"* ]]
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to