Home Ask Login Register

Developers Planet

Your answer is one click away!

mmm February 2016

bash ignores & for last command in loop

I just wrote my first bash script to start some redis instances on a development server. While it is mostly working, the last opened redis instance is blocking the active terminal – though I have the trailing & sign and the other started instances aren't blocking the terminal. How would I push them all to the background?

Here's the script:

REDIS=(6379 6380 6381 6382 6383 6390 6391 6392 6393)
for i in "${REDIS[@]}"
    redis-server --port $i &


that other guy February 2016

It sounds like your terminal is not actually blocked, your prompt just got overwritten. It's a purely cosmetic issue. Due to the way terminals work, bash doesn't know to redraw it so it looks like the command is in the foreground.

Run the script again, and blindly type lsEnter. You'll probably see that the shell responds as normal, even though you can't see the prompt.

You can alternatively just hit Enter to get bash to redraw the prompt.

Post Status

Asked in February 2016
Viewed 2,129 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life