parenthesis: purpose in the command line

Message
Author
Butters
Posts: 32
Joined: Wed Aug 21, 2019 2:26 am

parenthesis: purpose in the command line

#1 Post 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.

PPC
Posts: 362
Joined: Tue Sep 11, 2018 8:22 am

Re: parenthesis: purpose in the command line

#2 Post 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.

Butters
Posts: 32
Joined: Wed Aug 21, 2019 2:26 am

Re: parenthesis: purpose in the command line

#3 Post 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!

bll
Posts: 28
Joined: Thu Jun 01, 2017 11:04 am

Re: parenthesis: purpose in the command line

#4 Post 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.

User avatar
JayM
Posts: 6796
Joined: Tue Jan 08, 2019 3:47 am

Re: parenthesis: purpose in the command line

#5 Post 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
Last edited by JayM on Tue Jun 30, 2020 9:22 pm, edited 1 time in total.
Please read the Forum Rules, How To Ask For Help, How to Break Your System and Don't Break Debian. Always include your full Quick System Info (QSI) with each and every new help request.

Butters
Posts: 32
Joined: Wed Aug 21, 2019 2:26 am

Re: parenthesis: purpose in the command line

#6 Post 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.

User avatar
Mauser
Posts: 1496
Joined: Mon Jun 27, 2016 7:32 pm

Re: parenthesis: purpose in the command line

#7 Post 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. ;)
I am command line illiterate. :confused: I copy & paste to the terminal. Liars, Wiseguys, Trolls, and those without manners will be added to my ignore list. :mad:

User avatar
asqwerth
Developer
Posts: 7992
Joined: Sun May 27, 2007 5:37 am

Re: parenthesis: purpose in the command line

#8 Post 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
Desktop: Intel i5-4460, 16GB RAM, Intel integrated graphics
Clevo N130WU-based Ultrabook: Intel i7-8550U (Kaby Lake R), 16GB RAM, Intel integrated graphics (UEFI)
ASUS X42D laptop: AMD Phenom II, 6GB RAM, Mobility Radeon HD 5400

Butters
Posts: 32
Joined: Wed Aug 21, 2019 2:26 am

Re: parenthesis: purpose in the command line

#9 Post by Butters »

asqwerth wrote: Wed Jul 01, 2020 2:52 am 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
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!
:happy:

User avatar
seaken64
Posts: 819
Joined: Wed Jan 02, 2019 1:43 pm

Re: parenthesis: purpose in the command line

#10 Post 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
MX21-64 XFCE & W11 on Lenovo 330S LT. MX21-KDE & MX21-XFCE on Live USB.
MX18-64 & W7, Fedora on HP Core2 DT
MX21-32 XFCE w/ MX-Fluxbox on P4HT DT w/ antiX21, SUSE Tumbleweed, Q4OS, WXP
antiX21 on Compaq PIII 1 Ghz DT, w/ Debian, MX18FB, W2K

Post Reply

Return to “General”