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 a7acd69bf7b5a..bb36f913019eb 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 c004a30d999af..e320009bc7a9c 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,23 @@ 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" + + 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"* ]] +}