stuffy
stuffy

Reputation: 67

why does ''tput ed'' delete lines, instead of just clearing one line?

i want to rewrite first line but tput is removing all lines instead of first line

im testing this

cl=$(tput ed)
tput sc
echo 'line1____'
echo 'line2____'
echo 'line3____'
sleep 1
tput rc
echo "abc$cl"
echo ''
echo ''
sleep 1

when done it should look like

abc
line2____
line3____

but it is doing

abc
            -empty
            -empty

Upvotes: 0

Views: 112

Answers (1)

markp-fuso
markp-fuso

Reputation: 35296

I think what you want is tput el (clear to end of line) instead of tput ed (clear to end of screen):

cl=$(tput el)

From the man pages for terminfo:

     Variable            Cap-      TCap       Description
      String             name      Code

clr_eol                  el        ce     clear to end of line (P)
                         ^^               ^^^^^^^^^^^^^^^^^^^^

clr_eos                  ed        cd     clear to end of screen (P*)
                         ^^               ^^^^^^^^^^^^^^^^^^^^^^

When I make this one change (cl=$(tput el)) to your code it now generates:

abc
line2____
line3____

Upvotes: 1

Related Questions