Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am writing a script and acording to that when i run it certain info will be displayed on the output screen.

for example say the constant data displayed is:

my name is mukesh.
i am 27 years old
unix version 7.2.3.0

but along with the above display something else is also need to be displayed(varying data) i.e

Process A is starting
Process A is running
Process A is completed.

but i dont want the above display.

I want Process A is starting to be cleared from screen and replaced by Process A is running and then by Process A is completed.

i am not very keen to use clear as it will remove the whole screen containing the constant data also. and also because the constant data takes a lot of time to process and to be displayed on the screen.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

You can clear a line and use carriage return (\r) to get to the beginning of the line.

clr2eol=`tput el`                              # capture escape sequence for "clear-to-end-of-line"
echo -n "Process A has started."               # display without a newline
sleep 3
echo -n "\r${clr2eol}Process A is running."    # move to beginning of line (bol), clear, and display new text
sleep 5
echo -n "\r${clr2eol}Process A has completed." # again, move to bol, clear and display new test
echo                                           # terminating newline  you may not want to have this sent right away

Read the manpage on terminfo.

share|improve this answer
    
this one is good ......++++++1 –  munish Mar 9 '12 at 22:06

To do something like that you'll have to use some like (n)curses: http://www.gnu.org/software/ncurses/

share|improve this answer
    
i need to look into this ...new for me thanks again –  munish Mar 9 '12 at 21:48

The carriage return character (\r) will return to the beginning of the current line, so you can overwrite text:

printf "%s\r" "Process A is starting  "
sleep 5
printf "%s\r" "Process A is running   "
sleep 5
printf "%s\n" "Process A is completed."
share|improve this answer
    
+1 simple and easy....Thanks a lot @glenn –  munish Mar 9 '12 at 20:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.