Replace echo -e with printf for portability
Converted all echo -e commands to printf for better portability across different systems and shells. Printf is POSIX-compliant and behaves consistently. Updated functions: - colorize_health(): Uses printf %b for escape sequences - colorize_temp(): Uses printf %b for escape sequences - colorize_header(): Uses printf with newline - log_error(), log_warn(), log_info(): Uses printf for stderr Also simplified header output by calling colorize_header directly since it now handles its own newline. Fixes: #19 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -129,12 +129,12 @@ colorize_health() {
|
|||||||
local health="$1"
|
local health="$1"
|
||||||
if [[ "$USE_COLOR" == true ]]; then
|
if [[ "$USE_COLOR" == true ]]; then
|
||||||
if [[ "$health" == "✓" ]]; then
|
if [[ "$health" == "✓" ]]; then
|
||||||
echo -e "${COLOR_GREEN}${health}${COLOR_RESET}"
|
printf '%b%s%b' "$COLOR_GREEN" "$health" "$COLOR_RESET"
|
||||||
else
|
else
|
||||||
echo -e "${COLOR_RED}${health}${COLOR_RESET}"
|
printf '%b%s%b' "$COLOR_RED" "$health" "$COLOR_RESET"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$health"
|
printf '%s' "$health"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,14 +157,14 @@ colorize_temp() {
|
|||||||
temp_val="${temp_str%°C}"
|
temp_val="${temp_str%°C}"
|
||||||
if [[ "$temp_val" =~ ^[0-9]+$ ]]; then
|
if [[ "$temp_val" =~ ^[0-9]+$ ]]; then
|
||||||
if [[ "$temp_val" -ge 60 ]]; then
|
if [[ "$temp_val" -ge 60 ]]; then
|
||||||
echo -e "${COLOR_RED}${temp_str}${COLOR_RESET}"
|
printf '%b%s%b' "$COLOR_RED" "$temp_str" "$COLOR_RESET"
|
||||||
elif [[ "$temp_val" -ge 50 ]]; then
|
elif [[ "$temp_val" -ge 50 ]]; then
|
||||||
echo -e "${COLOR_YELLOW}${temp_str}${COLOR_RESET}"
|
printf '%b%s%b' "$COLOR_YELLOW" "$temp_str" "$COLOR_RESET"
|
||||||
else
|
else
|
||||||
echo -e "${COLOR_GREEN}${temp_str}${COLOR_RESET}"
|
printf '%b%s%b' "$COLOR_GREEN" "$temp_str" "$COLOR_RESET"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$temp_str"
|
printf '%s' "$temp_str"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,9 +176,9 @@ colorize_temp() {
|
|||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
colorize_header() {
|
colorize_header() {
|
||||||
if [[ "$USE_COLOR" == true ]]; then
|
if [[ "$USE_COLOR" == true ]]; then
|
||||||
echo -e "${COLOR_BLUE}${COLOR_BOLD}$1${COLOR_RESET}"
|
printf '%b%b%s%b\n' "$COLOR_BLUE" "$COLOR_BOLD" "$1" "$COLOR_RESET"
|
||||||
else
|
else
|
||||||
echo "$1"
|
printf '%s\n' "$1"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,9 +190,9 @@ colorize_header() {
|
|||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
log_error() {
|
log_error() {
|
||||||
if [[ "$USE_COLOR" == true ]]; then
|
if [[ "$USE_COLOR" == true ]]; then
|
||||||
echo -e "${COLOR_RED}ERROR:${COLOR_RESET} $1" >&2
|
printf '%bERROR:%b %s\n' "$COLOR_RED" "$COLOR_RESET" "$1" >&2
|
||||||
else
|
else
|
||||||
echo "ERROR: $1" >&2
|
printf 'ERROR: %s\n' "$1" >&2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,9 +205,9 @@ log_error() {
|
|||||||
log_warn() {
|
log_warn() {
|
||||||
if [[ "$VERBOSE" == true ]]; then
|
if [[ "$VERBOSE" == true ]]; then
|
||||||
if [[ "$USE_COLOR" == true ]]; then
|
if [[ "$USE_COLOR" == true ]]; then
|
||||||
echo -e "${COLOR_YELLOW}WARN:${COLOR_RESET} $1" >&2
|
printf '%bWARN:%b %s\n' "$COLOR_YELLOW" "$COLOR_RESET" "$1" >&2
|
||||||
else
|
else
|
||||||
echo "WARN: $1" >&2
|
printf 'WARN: %s\n' "$1" >&2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -221,9 +221,9 @@ log_warn() {
|
|||||||
log_info() {
|
log_info() {
|
||||||
if [[ "$VERBOSE" == true ]]; then
|
if [[ "$VERBOSE" == true ]]; then
|
||||||
if [[ "$USE_COLOR" == true ]]; then
|
if [[ "$USE_COLOR" == true ]]; then
|
||||||
echo -e "${COLOR_CYAN}INFO:${COLOR_RESET} $1" >&2
|
printf '%bINFO:%b %s\n' "$COLOR_CYAN" "$COLOR_RESET" "$1" >&2
|
||||||
else
|
else
|
||||||
echo "INFO: $1" >&2
|
printf 'INFO: %s\n' "$1" >&2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -851,7 +851,7 @@ if [[ "$SKIP_CEPH" != true ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
printf "\n"
|
printf "\n"
|
||||||
echo -e "$(colorize_header '=== Drive Details with SMART Status (by Bay Position) ===')"
|
colorize_header '=== Drive Details with SMART Status (by Bay Position) ==='
|
||||||
if [[ "$SHOW_PCI" == true ]]; then
|
if [[ "$SHOW_PCI" == true ]]; then
|
||||||
printf "%-5s %-15s %-10s %-8s %-8s %-8s %-30s %-20s %-12s %-10s %-10s %-30s %-40s\n" "BAY" "DEVICE" "SIZE" "TYPE" "TEMP" "HEALTH" "MODEL" "SERIAL" "CEPH OSD" "STATUS" "USAGE" "WARNINGS" "PCI PATH"
|
printf "%-5s %-15s %-10s %-8s %-8s %-8s %-30s %-20s %-12s %-10s %-10s %-30s %-40s\n" "BAY" "DEVICE" "SIZE" "TYPE" "TEMP" "HEALTH" "MODEL" "SERIAL" "CEPH OSD" "STATUS" "USAGE" "WARNINGS" "PCI PATH"
|
||||||
echo "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
|
echo "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
|
||||||
@@ -1007,7 +1007,7 @@ if [[ -n "$nvme_devices" ]]; then
|
|||||||
|
|
||||||
if [[ -n "$unmapped_nvme" ]]; then
|
if [[ -n "$unmapped_nvme" ]]; then
|
||||||
printf "\n"
|
printf "\n"
|
||||||
echo -e "$(colorize_header '=== Unmapped NVMe Drives ===')"
|
colorize_header '=== Unmapped NVMe Drives ==='
|
||||||
printf "%-15s %-10s %-10s %-40s %-25s\n" "DEVICE" "SIZE" "TYPE" "MODEL" "SERIAL"
|
printf "%-15s %-10s %-10s %-40s %-25s\n" "DEVICE" "SIZE" "TYPE" "MODEL" "SERIAL"
|
||||||
echo "------------------------------------------------------------------------------------------------------"
|
echo "------------------------------------------------------------------------------------------------------"
|
||||||
echo "$unmapped_nvme" | while read -r name size; do
|
echo "$unmapped_nvme" | while read -r name size; do
|
||||||
@@ -1032,7 +1032,7 @@ fi
|
|||||||
rbd_devices=$(lsblk -d -n -o NAME,SIZE,TYPE 2>/dev/null | grep "rbd" | sort -V)
|
rbd_devices=$(lsblk -d -n -o NAME,SIZE,TYPE 2>/dev/null | grep "rbd" | sort -V)
|
||||||
if [ -n "$rbd_devices" ]; then
|
if [ -n "$rbd_devices" ]; then
|
||||||
printf "\n"
|
printf "\n"
|
||||||
echo -e "$(colorize_header '=== Ceph RBD Devices ===')"
|
colorize_header '=== Ceph RBD Devices ==='
|
||||||
printf "%-15s %-10s %-10s %-30s\n" "DEVICE" "SIZE" "TYPE" "MOUNTPOINT"
|
printf "%-15s %-10s %-10s %-30s\n" "DEVICE" "SIZE" "TYPE" "MOUNTPOINT"
|
||||||
echo "------------------------------------------------------------"
|
echo "------------------------------------------------------------"
|
||||||
echo "$rbd_devices" | while read -r name size type; do
|
echo "$rbd_devices" | while read -r name size type; do
|
||||||
@@ -1046,7 +1046,7 @@ fi
|
|||||||
# Show mapping diagnostic info if DEBUG is set
|
# Show mapping diagnostic info if DEBUG is set
|
||||||
if [[ -n "$DEBUG" ]]; then
|
if [[ -n "$DEBUG" ]]; then
|
||||||
printf "\n"
|
printf "\n"
|
||||||
echo -e "$(colorize_header '=== DEBUG: Drive Mappings ===')"
|
colorize_header '=== DEBUG: Drive Mappings ==='
|
||||||
for key in "${!DRIVE_MAP[@]}"; do
|
for key in "${!DRIVE_MAP[@]}"; do
|
||||||
echo "Bay $key: ${DRIVE_MAP[$key]}"
|
echo "Bay $key: ${DRIVE_MAP[$key]}"
|
||||||
done | sort -n
|
done | sort -n
|
||||||
|
|||||||
Reference in New Issue
Block a user