Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
I dont know why, I wrote a script yesterday about select directory, then I find no matter what option I gave, I just wouldn't change directory.
So I wrote a script today which contains only one line.
Code:
cd /home
and I just failed, with no error message. Any ideas?
Additional, I'm not at /home
It's about scope. when you run the script it invokes a new shell, and it's within that shell instances that you change directory. When you finish the script, that shell terminates, so nothing inside the shell persists to the parent it was executed from. If you want to run a list of commands in your current shell, you'd source the file. run ". myscript" and you'll change directory. the source dot there is broadly like an "include" statement in programming languages.
It's about scope. when you run the script it invokes a new shell, and it's within that shell instances that you change directory. When you finish the script, that shell terminates, so nothing inside the shell persists to the parent it was executed from. If you want to run a list of commands in your current shell, you'd source the file. run ". myscript" and you'll change directory. the source dot there is broadly like an "include" statement in programming languages.
Then I find in a sub shell, pwd is still there, so Where can,I get to know the difference between bash and a sub shell.
I simply treat /bin/bash as a shell? Am I right?
Now I have some questions list here.
1:I invoke a sub ahell, where does this sub shell come from?
2:It's said that env variables is still supported in sub shell, why doesn't it have complete builtin command?
Thanks for your help.
Then I find in a sub shell, pwd is still there, so Where can,I get to know the difference between bash and a sub shell.
I simply treat /bin/bash as a shell? Am I right?
Bash is a shell (BASH -> Bourne Again SHell). The term bash shell is a pleonasm.
Quote:
Originally Posted by xeechou
1:I invoke a sub ahell, where does this sub shell come from?
From the mother shell (the initial shell started when logging in). A mothewr shell can spawn child shells, which in turn can spawn child shells.
Quote:
Originally Posted by xeechou
2:It's said that env variables is still supported in sub shell, why doesn't it have complete builtin command?
Thanks for your help.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.