简体   繁体   中英

bash: result of multiple echo commands with a delay on one line?

I'm learning the basics on bash scripting, and basically what I'm trying to do is have an output of "..." with a pause in between each period.

I've tried echo . ; sleep 1 ;echo . ; sleep 1 ; echo . ; sleep 1 echo . ; sleep 1 ;echo . ; sleep 1 ; echo . ; sleep 1 echo . ; sleep 1 ;echo . ; sleep 1 ; echo . ; sleep 1 and other ways but the output is always vertically, line by line. I'm aware of what ";" and "&&" does but I'm just learning, and the only way that seemed close was a "echo . `sleep 1 command... Is echo or sleep even the right command for this?

Sorry for being so dim-witted but I just can't figure this out!

if your are looking to echo ...

echo "..." ; sleep 1 ;echo "..." ; sleep 1 ; echo "..." ; sleep 1

echo as the name implies is to "output" and yes "sleep" is definitely the command you need to for pausing.

if you want to use echo and output ... on the same line three times. you can use

 echo -n "..." ; sleep 1 ;echo -n "..." ; sleep 1 ; echo -n "..." ; sleep 1

echo automatically prints a newline after its arguments. To suppress it, you might be able to use the -n option, but that isn't universally supported. Instead, use printf .

printf '.'; sleep 1; printf '.'; sleep 1; printf '.'; sleep 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM