Page 1 of 1
parenthesis: purpose in the command line
Posted: Tue Jun 30, 2020 4:56 pm
by Butters
Greetings,
I discovered that commands can be run in a sub shell, via encasing them between parenthesis.
$ ls -l
-- and --
$ (ls -l)
...will both give you the same output.
I understand that the latter runs in a sub shell. What I do not understand is a practical use for using the parenthesis.
Please explain, or please provide an example where using the parenthesis is beneficial.
Thank you.
Re: parenthesis: purpose in the command line
Posted: Tue Jun 30, 2020 5:26 pm
by PPC
This is not a bash programming forum, but here you go:
https://www.tldp.org/LDP/abs/html/subshells.html
FYI: I just googled the answer to your question. If you had done that you would not have to wait for an answer...
P.
Re: parenthesis: purpose in the command line
Posted: Tue Jun 30, 2020 5:47 pm
by Butters
PPC wrote: Tue Jun 30, 2020 5:26 pm
This is not a bash programming forum, but here you go:
https://www.tldp.org/LDP/abs/html/subshells.html
FYI: I just googled the answer to your question. If you had done that you would not have to wait for an answer...
P.
Which forum would have been the right one to ask my question. I looked at all of the descriptions, and none were exactly right for this subject.
I looked at the link that you provided. It explains the purpose of a sub-shell, but offered no practical example where the parenthesis is beneficial. It explained how variables are hidden and not available to the parent shell, etc.
And it was a tough read for me. I am not a Linux expert. I know only the basics.
I do not use google. They, along with Microsoft (especial Windows 10), are the leading spyware companies, the likes of which the world has never seen.
Cheers!
Re: parenthesis: purpose in the command line
Posted: Tue Jun 30, 2020 6:04 pm
by bll
The 'dedicated environment' section on that web page is one of the common uses.
e.g.
tar -c -f - ./mystuff | (cd /home/otheruser/tmp; tar -x -f -)
The second tar command has its own working directory. This was common before tar gained a -C option.
Combining output:
(cat a; hd a) > all.txt
And I think "google" means "search on the internet using your favorite search engine". He doesn't care if you actually use google.
Re: parenthesis: purpose in the command line
Posted: Tue Jun 30, 2020 7:38 pm
by JayM
Butters wrote: Tue Jun 30, 2020 5:47 pm
PPC wrote: Tue Jun 30, 2020 5:26 pm
This is not a bash programming forum, but here you go:
https://www.tldp.org/LDP/abs/html/subshells.html
FYI: I just googled the answer to your question. If you had done that you would not have to wait for an answer...
P.
Which forum would have been the right one to ask my question. I looked at all of the descriptions, and none were exactly right for this subject.
A web search could tell you that too. I think what PPC is telling you is that forum.mxlinux.org is a support forum specifically for people having problems with the MX and antiX Linux distros, not a gereric computer or programming help forum.
I do not use google. They, along with Microsoft (especial Windows 10), are the leading spyware companies, the likes of which the world has never seen.
Google doesn't have a monopoly on web search engines.
https://en.wikipedia.org/wiki/List_of_search_engines
Re: parenthesis: purpose in the command line
Posted: Tue Jun 30, 2020 8:59 pm
by Butters
bll wrote: Tue Jun 30, 2020 6:04 pm
Combining output:
(cat a; hd a) > all.txt
Yes, the above example makes sense to me. Thanks for the help.
But this example...:
bll wrote: Tue Jun 30, 2020 6:04 pm
tar -c -f - ./mystuff | (cd /home/otheruser/tmp; tar -x -f -)
The second tar command has its own working directory. This was common before tar gained a -C option.
...is above my pay grade. I understand tar's function. But I do not understand how the shell will unravel the entire set of instructions.
I see that it will create a new file in the current directory, and I see after the pipe that the directory gets set and tar extracts the contents of the file. But when all is said and done, do the contents of the tar file wind up in the /home/otheruser/temp directory?
Is that the entirety of your example? Am I understanding it correctly?
bll wrote: Tue Jun 30, 2020 6:04 pm
And I think "google" means "search on the internet using your favorite search engine". He doesn't care if you actually use google.
I try to minimize assuming what people mean -- especially in a technical forum where some folks are literal to a fault.
When someone writes use "google", then I lean towards them meaning what they wrote.
I write use "duckduckgo" when suggesting a search engine. Or I write that they should use the search engine of their choice.
bll wrote: Tue Jun 30, 2020 6:04 pm
The 'dedicated environment' section on that web page is one of the common uses.
On which web page? On this one?:
https://www.tldp.org/
(this is the first time I have been to the above site)
I am not sure what you mean by dedicated environments and common uses.
I do not want to repeat any mistakes. So I am asking in an effort to understand.
Thank you.
Re: parenthesis: purpose in the command line
Posted: Wed Jul 01, 2020 12:36 am
by Mauser
Butters wrote: Tue Jun 30, 2020 5:47 pm
PPC wrote: Tue Jun 30, 2020 5:26 pm
This is not a bash programming forum, but here you go:
https://www.tldp.org/LDP/abs/html/subshells.html
FYI: I just googled the answer to your question. If you had done that you would not have to wait for an answer...
P.
I do not use google. They, along with Microsoft (especial Windows 10), are the leading spyware companies, the likes of which the world has never seen.
Cheers!
I agree with you on Gagle and MicroSpy. That's why I Duck it and use MX Linux.

Re: parenthesis: purpose in the command line
Posted: Wed Jul 01, 2020 2:52 am
by asqwerth
The same way "hoover" became a generic term to mean "vacuum", "google" is fast becoming a generic term to mean "do a web search".
https://en.wikipedia.org/wiki/List_of_g ... trademarks
Re: parenthesis: purpose in the command line
Posted: Wed Jul 01, 2020 9:35 am
by Butters
I never use google as a verb.
I never recommend google as a search engine.
I always dissuade people from all google and all Microsoft products, and closed code in general.
I would hope that in a forum, for open-source code, the community would not follow the masses off the google spyware cliff.
If not in a Linux open-source community, then where?
By the way, I do not use Jello, Rollerblade, Xerox, etc.
I use gelatin, in-line skates, copy, etc.
Cheers!

Re: parenthesis: purpose in the command line
Posted: Fri Jul 03, 2020 7:26 pm
by seaken64
As you wish Butters. You're welcome to do whatever you want.
Personally, I use Google. And Kleenex, Coke, Jello, Skillsaw, etc. etc.
I don't see the sense in objecting philosophically to someone suggesting you use "Google". Just go ahead and translate it however you want and move on.
The point was that if you used a search engine you wouldn't have to wait for forum members to comment.
I don't mind the discussion at all. I'm always interested in learning more about the command line.
Seaken64