Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:21:23+00:00 2026-06-01T10:21:23+00:00

After trying to figure out why a Capistrano task (which tried to start a

  • 0

After trying to figure out why a Capistrano task (which tried to start a daemon in the background) was hanging, I discovered that using && in bash over ssh prevents a subsequent program from running in the background. I tried it on bash 4.1.5 and 4.2.20.

The following will hang (i.e. wait for sleep to finish) in bash:

ssh localhost "cd /tmp && nohup sleep 10 >/dev/null 2>&1 &"

The following won’t:

ssh localhost "cd /tmp ; nohup sleep 10 >/dev/null 2>&1 &"

Neither will this:

cd /tmp && nohup sleep 10 >/dev/null 2>&1 &

Both zsh and dash will execute it in the background in all cases, regardless of && and ssh. Is this normal/expected behavior for bash, or a bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:21:25+00:00Added an answer on June 1, 2026 at 10:21 am

    One easy solution is to use:

    ssh localhost "(cd /tmp && nohup sleep 10) >/dev/null 2>&1 &"
    

    (this also works if you use braces, see second example below).

    I did not experiment further but I am reasonably convinced it has to do with open file descriptors hanging around. Perhaps zsh and dash bind the && so that this means what has to be spelled as:

    { cd /tmp && nohup sleep 10; } >/dev/null 2>&1
    

    in bash.


    Nope, quick experiment in dash shows that echo foo && echo bar >file only redirects the latter. Still, it has to have something to do with lingering open fd’s causing ssh to wait for more output; I’ve run into this a lot in the past.


    One more trick, not needed if you use the parentheses or braces for this particular case but might be useful in a more general context, where the set of commands to do with && are more complex. Since bash seems to be hanging on to the file descriptor inappropriately with && but not with ;, you can turn a && b && c into a || exit 1; b || exit 1; c. This works with the test case:

    ssh localhost "true || exit 1; echo going on; nohup sleep 10 >/dev/null 2>&1 &"
    

    Replace true with false and the echo of “going on” is omitted.

    (You can also set -e, although sometimes that is a bigger hammer than desired.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out the data structure that is stored in 'buffer' after
After so many years using ASP.Net, I’m still trying to figure out how to
I'm trying to figure out how to show validation errors after a user submits
I am trying to figure out how to do the following: 1) After a
I'm trying to figure out how to get the users information after validating via
after one day of trying to figure out how to implement a kd-tree in
I'm trying to figure out how to strip content after the closing HTML tag
I'm trying to figure out why the frame of a UIScrollView is changing after
I'm trying to figure out the best option to use anonymous event listeners that
I'm trying to figure out the differences between a task.LoopingCall and a reactor.callInThread in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.