DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 16th March 2018
vanGrimoire's Avatar
vanGrimoire vanGrimoire is offline
Port Guard
 
Join Date: Nov 2012
Posts: 43
Default Subshells

What is the difference between the various subshells?

$ $(firefox)
$ firefox &
[1] 69537
$ `firefox`
[1] + Done firefox
$ firefox &&
> echo hello world!
hello world!

Sorry if this is vague, but are there advantages and disadvantages or are they basically different means of skinning the same cat?
Reply With Quote
  #2   (View Single Post)  
Old 16th March 2018
Beastie Beastie is offline
Daemonology student
 
Join Date: Jan 2009
Location: /dev/earth0
Posts: 335
Default

It's not a matter of there being any particular advantage or disadvantage to using one or another. These are different ways of executing commands and doing job control. Each has it's use.

Quote:
Originally Posted by vanGrimoire View Post
$ firefox &
The single ampersand executes the command in the background (in other words, it doesn't block the shell while the process is running: it runs the command, "detaches" it from the shell and returns to the shell right away).

Quote:
Originally Posted by vanGrimoire View Post
$ `firefox`
A pair of grave accents is used for command substitution. It's normally used within another command such as echo Hello, `id -un`! (the id(1) command within the echo(1) command).
In your case, since there's nothing else, it simply runs the command.

Quote:
Originally Posted by vanGrimoire View Post
$ firefox &&
> echo hello world!
The double ampersand is a logical operator (conditional AND).
The second command after the && runs only if the first command returns successfully. In your case you didn't specify that second command so the shell opened a subshell so that you can type and run it.
You could've just run firefox && echo hello world!


You're not using these features in a very "creative" way (no offense intended), that's why they feel similar. Their usefulness becomes more apparent when used within elaborate shell scripts.
__________________
May the source be with you!
Reply With Quote
  #3   (View Single Post)  
Old 17th March 2018
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 1,027
Default

To comment on the other (first) example in the OP

$ $( command )

is just another syntax for

$ ` command `

Both do the same thing: command is run and its standard output is substituted in place of $( command ), in the cmd line where it occurred. Normally the command would be chosen to output some useful text that you want to insert in the original cmd line; firefox probably doesn't do this.

For more detail you should study the man page for your shell in the areas where these are described. There are all kinds of weird/cool things that can be done.
Reply With Quote
  #4   (View Single Post)  
Old 17th March 2018
vanGrimoire's Avatar
vanGrimoire vanGrimoire is offline
Port Guard
 
Join Date: Nov 2012
Posts: 43
Default Right on!

I was getting at that (grave accents vs parens), but my power blipped.

I did find,

Code:
#!/bin/ksh
firefox &
ff_pid=$!
which is embarrassingly easier than awk,

Last edited by vanGrimoire; 17th March 2018 at 02:21 AM. Reason: added shell
Reply With Quote
  #5   (View Single Post)  
Old 17th March 2018
vanGrimoire's Avatar
vanGrimoire vanGrimoire is offline
Port Guard
 
Join Date: Nov 2012
Posts: 43
Default

Sorry the purpose was to start an application from the CLI, return the shell and not fill it up with debug logs, etc.

I think
Code:
supertux2 2> /dev/null &
is what I'm looking for.
Reply With Quote
Reply

Tags
openbsd, subshell

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:29 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick