Sample Header Ad - 728x90

Command substitution used with tput which doesn't print anything

0 votes
1 answer
37 views
I am doing a code-study of /lib/lsb/init-functions on mint 20 just to familiarise myself with SystemV init system. There is log_action_end_msg function in it which has this code snippet,
TPUT=/usr/bin/tput
if log_use_fancy_output; then
            RED=$( $TPUT setaf 1)  #=> Step 1
            NORMAL=$( $TPUT op)    #
            /bin/echo -e "${RED}failed${end}${NORMAL}" || true #=> Step 2
else
            echo "failed${end}" || true
fi
when the variable RED is assigned the value of $( $TPUT setaf 1 ), i expect RED to be assigned an empty string, since tput run on command-line doesn't print any stuff. But, I see the variable is passed onto echo in Step 2 implying that it has something stored in it. How does the variable RED get set, when tput doesn't print anything? (Or) Let us leave aside all the other stuffs. Take a fresh terminal and just run RED=$( $TPUT setaf 1) on my terminal and i expect terminal font color to be set as red but it is not so. Only when i do echo $RED, it turns red. Why is that tput command not getting run during the substitution step, but runs when you invoke echo.
Asked by Saravana (193 rep)
Feb 3, 2025, 08:13 PM
Last activity: Feb 3, 2025, 10:19 PM