SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You're all pretty clever people here, so I can't think of a better place to ask this actually. It might seem like a weird question, but please bare with me.
So, I'm looking into different ways to execute and invoke bash from bash, and I'm hoping some of you guys can add a method or two here that I can study further. The purpose mainly is in regards to different exclusive executions of bash, in the same shell, but in particular in subshells and subshells of subshell etc.
Now, I've come up with a few different ways to do it myself, about 10 that has widely different implications in terms of execution path and context. And yes, executing bash through a script/file is also included as an option (and each different file would be two distinct ways actually).
Which would mean that executing bash like below, are all different ways (despite all except the last, in a way, is the same):
/bin/bash
bash
sh bash
sh /bin/bash
sh bashexecute.script (content: /bin/bash)
Or something like (sudo) su and (sudo) su - in regards to subshells..
Anyways, not too complicated please, but if anyone have some other ways to add here, it would be greatly appreciated. And of particular interest is descending into various subshells. I also don't mind if you even have some tips in regards to agetty and login in the same context.
Let's assume for the sake of it/rules that the starting point is agetty/login/bash in tty1 and we don't have a GUI (but we do have /dev/fb0).
That's unless you have some additional tips in regards to agetty or login.
Ok, I realize that you might know a 100 ways to do this. But if you do, don't list them all, give me your best shot, just a single one you think is relevant to add here, or your top 3 picks.
what do you want to study?
if you have sh bash you can have zsh bash, ksh bash or dash bash or any other combinations of any other shells.
And you can invoke bash from ssh and from a lot of other tools (like perl, python, java, php, ruby, .....).
if you have sh bash you can have zsh bash, ksh bash or dash bash or any other combinations of any other shells.
Yes, but sh is actually bash, a subset of bash anyways. And I did considering invoking bash with other shells, but I decided I wanted to stick with bash shell only and not the other ones.
Quote:
Originally Posted by pan64
And you can invoke bash from ssh and from a lot of other tools (like perl, python, java, php, ruby, .....).
Any specific good examples? (that you can do from tty1 agetty/login/bash)
And to be frank, ssh, maybe, but I wouldn't consider python, java and php good examples. Slackware also doesn't come with java as far as I know. But the point is local execution mainly or at least pseudo local (ssh?). Trying to keep it simple also in my opinion would avoid complex executioners
But executioniers are absolutely relevant, but preferably simple ones. I'm not a big fan of pkexec, but that's one that I can think of at the top of my head.
Yes, but sh is actually bash, a subset of bash anyways. And I did considering invoking bash with other shells, but I decided I wanted to stick with bash shell only and not the other ones.
No, that is wrong. sh is a different shell, using different syntax. Actually the binary can work (act) as bash and as sh too, but on some systems you may find two different binaries too.
Quote:
Originally Posted by zeebra
Any specific good examples? (that you can do from tty1 agetty/login/bash)
ssh/agetty/login will (may) automatically start bash. What kind of example do you need?
Quote:
Originally Posted by zeebra
And to be frank, ssh, maybe, but I wouldn't consider python, java and php good examples. Slackware also doesn't come with java as far as I know. But the point is local execution mainly or at least pseudo local (ssh?). Trying to keep it simple also in my opinion would avoid complex executioners
But executioniers are absolutely relevant, but preferably simple ones. I'm not a big fan of pkexec, but that's one that I can think of at the top of my head.
Every and each application works the same way, starting a new app is a two-step process: 1. clone the current environment, 2. exec the new binary (= bash in your case).
No, that is wrong. sh is a different shell, using different syntax. Actually the binary can work (act) as bash and as sh too, but on some systems you may find two different binaries too.
ssh/agetty/login will (may) automatically start bash. What kind of example do you need?
Every and each application works the same way, starting a new app is a two-step process: 1. clone the current environment, 2. exec the new binary (= bash in your case).
Ok, I don't have a problem anyways, so there is no stress to get anything solved, just a pleasant conversation about the topic, in theory and in practice.
I hate to argue, but on my system the real execution path of "sh" is /bin/bash, which in my opinion is bash in "sh" mode, or a subset of bash. But well, I could be wrong, but that's how it looks at least to me.
This actually reminds me there is a /usr/bin/bash, which would in the context of this topic be another execution of bash, although it simply points to /bin/bash, but the execution file/context is different.
pipeline - in a pipeline each command separate by | or |& is executed it's own subshell
Thanks, that is very useful indeed. It makes me rethink my approach. One of the things I did try was a simple script file to execute /bin/bash in a subshell and descend into it and then execute /bin/bash from there and descend into it.
I tried all kind of combinations with arguments -i and -l, but in the end I failed to accomplish what I wanted. I was experimenting quite alot and did it in different ways with () and |, and in one instance I did succeed in doing what I wanted, which was to go from agetty/login/bash and descend directly into a third subshell of bash. But I failed to reproduce it, and I don't know what cause it to succeed.
Later attempts simply created 3 single subshells of bash where I descended into the first one.
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.
we have a variable SHLVL which will show you the "levels" of your subshells.
also you can use the commands env and set to see how is your current shell configured and compare it to another shell or another subshell (if you wish)
we have a variable SHLVL which will show you the "levels" of your subshells.
also you can use the commands env and set to see how is your current shell configured and compare it to another shell or another subshell (if you wish)
Now that's very helpful for these kind of experiments as they sometimes can get very confusing very fast. Including auditing each action.
Code:
SHLVL=3
Currently. But just from running a couple of minor checks in Konsole.
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.
bash is able to detect its own invocation (as any other program on linux/unix) and act upon that. So /bin/bash, /bin/sh, /bin/rbash and others may point to the same binary, but using different names will cause different behavior.
It works with vi too, it can also be invoked as vim, ex, view, rvim (for example).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.