LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-08-2022, 08:25 AM   #16
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,377

Rep: Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757

Another bash variable is BASH_SUBSHELL. An example of descending subshells by command grouping.
Code:
bash-5.1$ echo "here $BASH_SUBSHELL";(echo "here $BASH_SUBSHELL";(echo "here $BASH_SUBSHELL";(echo "here $BASH_SUBSHELL")))
here 0
here 1
here 2
here 3
 
1 members found this post helpful.
Old 06-08-2022, 08:31 AM   #17
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,834

Original Poster
Blog Entries: 17

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
In that case I would think if you add the -l option on the third one, that will become your current shell, or?
 
Old 06-08-2022, 08:56 AM   #18
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,982

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
Quote:
Originally Posted by zeebra View Post
In that case I would think if you add the -l option on the third one, that will become your current shell, or?
no
-l means login shell. see man page about invocation, that will explain what is the difference between a login and non-login shell.
and you can also check the importance of interactive (and non-interactive) shells
 
Old 06-08-2022, 10:29 AM   #19
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,834

Original Poster
Blog Entries: 17

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
Quote:
Originally Posted by pan64 View Post
no
-l means login shell. see man page about invocation, that will explain what is the difference between a login and non-login shell.
and you can also check the importance of interactive (and non-interactive) shells
That makes another interesting point actually. Assuming you are already root, if it is possible to force /bin/login on a third subshell of bash before you can use it

I'll have to look closer into login too. On first glance, that doesn't seem to be possible (recursive login). What should be possible is to replace it with a simple private login facility.

Last edited by zeebra; 06-08-2022 at 10:37 AM.
 
Old 06-08-2022, 11:05 AM   #20
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,982

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
bash -l will not invoke login again, it will just work differently [again] with -l and without -l
 
Old 06-08-2022, 11:30 AM   #21
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,834

Original Poster
Blog Entries: 17

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
Quote:
Originally Posted by pan64 View Post
bash -l will not invoke login again, it will just work differently [again] with -l and without -l
Then what is it that actually determines which shell I end up in/viewing.
 
Old 06-08-2022, 11:41 AM   #22
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,982

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
Quote:
Originally Posted by zeebra View Post
Then what is it that actually determines which shell I end up in/viewing.
better to read the man page. Different invocations usually mean different setup, at the end a new environment is created. All the subshells and subprocesses will inherit this environment, and the behavior can be also altered (like where is the DISPLAY), but it doesn't really matter how it was created.
 
Old 06-08-2022, 11:46 AM   #23
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,834

Original Poster
Blog Entries: 17

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
Quote:
Originally Posted by michaelk View Post
I don't know how slack is configured but in many distributions /bin/sh is just a link to whatever default shell it uses i.e. bash, dash etc. In addition /bin is also just a link to /usr/bin. So basically all paths point to the same thing. It is not a subset or different mode.
It is indeed so in Slackware too, but even so the execution context of /usr/bin/bash and /bin/bash is different, like bash and /bin/bash in my first post.
 
Old 06-08-2022, 11:51 AM   #24
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,982

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
the location of the binary is usually completely irrelevant, so /usr/bin/bash, /bin/bash and <any_other_location>/bash will behave exactly the same. And does not depend on the distro too (but how it was invoked and what was the actual name of it).
 
Old 06-08-2022, 12:11 PM   #25
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,834

Original Poster
Blog Entries: 17

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
Quote:
Originally Posted by pan64 View Post
better to read the man page. Different invocations usually mean different setup, at the end a new environment is created. All the subshells and subprocesses will inherit this environment, and the behavior can be also altered (like where is the DISPLAY), but it doesn't really matter how it was created.
Yeah, ofcourse, you would think so, but these things aren't exactly common use cases or easy to figure out either. I could ofcourse just search it online too, but past experience have shown me time and time again that uncommon use cases and solutions to them are nearly impossible to find good documentation on with search engines, and that you rather find common use cases that will not help you understand or accomplish what you actually need.

I was actually reading the online bash manual the other day:
https://www.gnu.org/software/bash/manual/bash.html

And I don't agree it's better to read the man pages.
They certainly don't cover many different ways to invoke or execute bash, not even just the few I mentioned.
And while it does cover subshells extensively, it's not exactly useful in answering my question either. That's kind of why you have teachers in similar situations in learning institutions. If there is something you don't understand, you can ask the teacher and they can try to help explain it in a way that you can understand. Two way communication, questions and all.

But hey, if you don't know either, it's ok to say so.

So, different contexts, yet again, even with the manual. And subshells is just a subquestion too, they aren't really THAT important. The main question is about different ways to invoke and execute bash. I mentioned quite a few, and I'm interested in some other (simple) ways that other people might know (that I don't).
 
Old 06-08-2022, 12:13 PM   #26
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,834

Original Poster
Blog Entries: 17

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
Quote:
Originally Posted by pan64 View Post
the location of the binary is usually completely irrelevant, so /usr/bin/bash, /bin/bash and <any_other_location>/bash will behave exactly the same. And does not depend on the distro too (but how it was invoked and what was the actual name of it).
I don't want to be snarky here, but please do fire up auditd, give the examples above a try and have a look at the differences. They most certainly ARE different, and in the security context that is highly relevant.

Last edited by zeebra; 06-08-2022 at 12:16 PM.
 
Old 06-08-2022, 12:40 PM   #27
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,982

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
yes, the security context can be different. But if you can execute them the result will be exactly the same.
 
Old 06-08-2022, 12:59 PM   #28
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,834

Original Poster
Blog Entries: 17

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
Quote:
Originally Posted by pan64 View Post
yes, the security context can be different. But if you can execute them the result will be exactly the same.
Well, the question in my post is quite simple actually, so the background doesn't/shouldn't matter anyway and would just be a waste of time and overcomplicate everything.

But, just briefly an example. My username can't do anything in bash at all, except launch Wayland and..
Code:
sh /folder/file1.execute.bash
Which means my user can use sh, but the only thing the user can do in sh is execute that "secret" file. And even though the file just contains /bin/bash, my user can't execute /bin/bash without that file. And if it was another file /folder/file2 containing the exact same thing, my user wouldn't be able to execute bash that way either, nor can the user /bin/bash /folder/file1.

Because it's all different contexts. Anyways, where things get more interesting and complicated is root, because you could/want to do much more. So context is absolutely super important in creating say 10 different instances (unique execution context) of /bin/bash that can only do certain things. But also if you want a "secret bash" that isn't that strict.

Anyways, that's not the only reason, but some of the background for the weird questions. But also in further understanding some non typical bash stuff that isn't included in standard documentation, but rather things that people "find out" with experience. Anyways, I do think we all know a bunch of different stuff that isn't easy to learn or understand, and that we can all learn from each others and draw from the experiences of eachother as well.

Last edited by zeebra; 06-08-2022 at 01:01 PM.
 
Old 06-09-2022, 01:55 AM   #29
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,834

Original Poster
Blog Entries: 17

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
So I guess subshells might be a dead end in regards to "different ways to execute bash".. And thanks to everyone for contributing, it has been immensly helpful in experimenting further and trying to understand how bash actually works, looking at it from outside of bash, and how shells work together. I still think I would have a bit of an issue drawing a diagram with the difference between subshells and nested shells though

Anyways, back to the different ways to execute bash, is not only interesting to me in the context of bash, but also interesting in regards to different ways to execute anything, outside of exec/fork, like forcing executions through certain binaries, and what kind of binaries are actually able to do simple executions in a simple way.
 
Old 06-09-2022, 04:02 AM   #30
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,982

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
there is no other way to start a process, but clone/fork and exec.
Subshell is just a new [bash] process started by the parent process.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to invoke a different java version ? sysmicuser Linux - Newbie 12 12-19-2017 07:53 AM
[SOLVED] BASH - Invoke commands when trap is activated worm5252 Programming 1 10-04-2011 04:54 PM
[SOLVED] How to invoke the calculator "bc" in bash script for floating point arithmetic? bluesmodular Programming 2 05-15-2010 11:58 PM
LXer: 15 Ways Nokia’s N900 Is Better Than Apple’s iPhone (and 5 ways it’s not) LXer Syndicated Linux News 0 11-14-2009 08:20 AM
have my .cshrc or .login invoke bash mattie_linux Linux - Newbie 1 06-06-2007 03:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 12:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration