tags:

views:

38

answers:

3

Hello,

Want to do a fancy effect by printing [OK] at the end of the last line when a task is finished.

Got this:

echo "$0: Starting backup process in '$backupdir'... " 
sleep 3
echo '[OK]'

I tried different things at the end of the first echo, at the beginning of the second like \r, \c, \, Googled it... No good.

I want it to output this:

./backup.sh: Starting backup process in '/backup'...

... And 3 sec later, add the [OK]:

./backup.sh: Starting backup process in '/backup'... [OK]

Thanks,

+5  A: 
echo -n "$0: Starting backup process in '$backupdir'... " 
Johan
+3  A: 

use the more portable printf

ghostdog74
Portable in what way?
Johan
see here: http://en.wikipedia.org/wiki/Echo_%28command%29#cite_note-0
ghostdog74
Some implementations of echo use the `-n` flag to suppress the newline; others use `\c` at the end of the string. If you use one in your script, and echo expects the other, you'll get "-n " in front of your output, or "\c" at the end. But `printf "%s" "$0: ..."` will always work as expected.
Gordon Davisson
@Gordon Davisson @ghostdog74, Could not agree more, even the POSIX standard says "New applications are encouraged to use printf instead of echo.". +1
Anders
Interesting. Thanks.
Johan
A: 

echo -n hello

ULysses