Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    Exhaustively good answer. Commented Feb 27, 2016 at 0:55
  • Does the subshell variation need curly braces for the function definition? Commented Feb 27, 2016 at 2:47
  • @JeffSchaller No, since it uses parentheses, precisely to make the body execute in a subshell. Commented Feb 27, 2016 at 11:41
  • I had this issue with alias CLONE='nohup konsole --workdir "$(pwd)" &>/dev/null &' and alias REFRESH='CLONE; exit'. This worked until recently on my bash. Removing the ; makes it work again but I don't like that too much and dont understand how a backgrounding & stops me from following with ;; is it actually the same issue, or just coincidentally the same solution? Commented Mar 5, 2018 at 7:19
  • 1
    @Hashbrown It's the same issue. The reason is that & and ; in fact have the same role in the shell grammar: they terminate a simple command, and which one you use determines whether the command is executed in the foreground or in the background. They only appear to have different roles because semicolons are used rarely: usually they're conveyed by a newline, which means “if a command terminator is expected, pretend there was a ;, else ignore the newline”. alias REFRESH=$'CLONE\n exit' should work in all bash versions except antique ones. Use an actual newline instead for portability. Commented Mar 5, 2018 at 18:27