Overwrite last line on terminal

后端 未结 6 963
耶瑟儿~
耶瑟儿~ 2020-12-23 02:21

My bash-script looks as following:

echo \"Description:\"
while [ $finishInput -eq 0 ]; do
read tmp
desc=\"$desc\"$\'\\n\'\"$tmp\"
if [ -z \"$tmp\" ]; then
fi         


        
6条回答
  •  太阳男子
    2020-12-23 02:51

    If you echo without the newline character echo -n "Something", you can use \r with your next echo to move the 'cursor' to the beginning of the line echo -e "\\rOverwrite something".

    #!/bin/bash
    
    CHECK_MARK="\033[0;32m\xE2\x9C\x94\033[0m"
    
    echo -e "\n\e[4mDoing Things\e[0m"
    echo -n "doing thing 1..."
    sleep 1
    echo -e "\\r${CHECK_MARK} thing 1 done"
    

    Just be aware that if your new string is shorter that your old string, the tail of your old string will still be visible. Note the done.. in the gif above.

提交回复
热议问题