Skip to main content
added 18 characters in body
Source Link
mattdm
  • 41.3k
  • 18
  • 104
  • 140

There's no native bash (or, to my knowledge, any other typical *nix shell) way of doing this. There's a lot of ways to spawn forked processes that do something else asynchronously, but I don't think there's anything that follows the exact semantics of the fork() system call.

The typical approach would be to have your top-level script spawn off helpers that do just the work you want split out. If you do $0 $@ & or whatever, you'll start at the beginning again and need to figure that out somehow.

I'm actually starting to think of several clever ways in which one might do just that....

But, before my brain gets too carried away with that, I think a pretty good rule is: if you're trying to write something in shell and it's getting full of clever tricks and you're wishing for more language features, time to switch to a real programming languageit's time to switch to a programming language with those features.

There's no native bash (or, to my knowledge, any other typical *nix shell) way of doing this. There's a lot of ways to spawn forked processes that do something else asynchronously, but I don't think there's anything that follows the exact semantics of the fork() system call.

The typical approach would be to have your top-level script spawn off helpers that do just the work you want split out. If you do $0 $@ & or whatever, you'll start at the beginning again and need to figure that out somehow.

I'm actually starting to think of several clever ways in which one might do just that....

But, before my brain gets too carried away with that, I think a pretty good rule is: if you're trying to write something in shell and it's getting full of clever tricks and you're wishing for more language features, time to switch to a real programming language.

There's no native bash (or, to my knowledge, any other typical *nix shell) way of doing this. There's a lot of ways to spawn forked processes that do something else asynchronously, but I don't think there's anything that follows the exact semantics of the fork() system call.

The typical approach would be to have your top-level script spawn off helpers that do just the work you want split out. If you do $0 $@ & or whatever, you'll start at the beginning again and need to figure that out somehow.

I'm actually starting to think of several clever ways in which one might do just that....

But, before my brain gets too carried away with that, I think a pretty good rule is: if you're trying to write something in shell and it's getting full of clever tricks and you're wishing for more language features, it's time to switch to a programming language with those features.

Source Link
mattdm
  • 41.3k
  • 18
  • 104
  • 140

There's no native bash (or, to my knowledge, any other typical *nix shell) way of doing this. There's a lot of ways to spawn forked processes that do something else asynchronously, but I don't think there's anything that follows the exact semantics of the fork() system call.

The typical approach would be to have your top-level script spawn off helpers that do just the work you want split out. If you do $0 $@ & or whatever, you'll start at the beginning again and need to figure that out somehow.

I'm actually starting to think of several clever ways in which one might do just that....

But, before my brain gets too carried away with that, I think a pretty good rule is: if you're trying to write something in shell and it's getting full of clever tricks and you're wishing for more language features, time to switch to a real programming language.