How to show and update echo on same line

前端 未结 6 1285
陌清茗
陌清茗 2020-11-27 11:27

I have the following in Bash (In Linux)

for dir in Movies/*
do
  (cd \"$dir\" && pwd|cut -d \\/ -f5|tr -s \'\\n\' \', \' >> ../../movielist &am         


        
6条回答
  •  难免孤独
    2020-11-27 12:09

    Well I did not read correctly the man echo page for this.

    echo had 2 options that could do this if I added a 3rd escape character.

    The 2 options are -n and -e.

    -n will not output the trailing newline. So that saves me from going to a new line each time I echo something.

    -e will allow me to interpret backslash escape symbols.

    Guess what escape symbol I want to use for this: \r. Yes, carriage return would send me back to the start and it will visually look like I am updating on the same line.

    So the echo line would look like this:

    echo -ne "Movie $movies - $dir ADDED!"\\r

    I had to escape the escape symbol so Bash would not kill it. that is why you see 2 \ symbols in there.

    As mentioned by William, printf can also do similar (and even more extensive) tasks like this.

提交回复
热议问题