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.
There is an additional problem in number 3: Linux uses whitespace as delimiters between command-line options, so if you want to assign a string containing a space, you need to quote the string thus:
should tell name equals to 1. After this you should use export like
Code:
export name
and after this you could see the variable, not by typing $name (which tells bash it's a program called $name) but using echo instead:
Code:
echo $name
The export is not necessary (at least in all situations) but might help.
EDIT: and I swear I just saw only three persons active on this thread..where did those other come from? Huh? And why haven't they *still* read my suggestion about an answer-lock of some kind to prevent a waste of posts like this..
The export is not necessary (at least in all situations) but might help.
Correct - export is only necessary if you wish other programs to be able to access your variable. For example, if you are setting an environment variable that another program runs. If you don't export the variable, its scope is treated as being local to the shell/script (depending on where it's being set) - i.e. not part of the environment.
to get some more (possibly unneeded) information. Though that "aux" combination doesn't seem to work on every ps command I've encountered..
EDIT:
Quote:
Correct - export is only necessary if you wish other programs to be able to access your variable. For example, if you are setting an environment variable that another program runs. If you don't export the variable, its scope is treated as being local to the shell/script (depending on where it's being set) - i.e. not part of the environment.
Thanks - that's by far the best (compact) explanation for "export" I've heard.
I think the "export" command needs more explanation. When you start a program, it inherits the environment with variables defined such as $HOME. Your program, let's call it "parent", might define one or more variables. Defining a variable places it in local memory and not the environment. If you call another program in the "parent" program, let's call it child, the variables you set will not be defined in "child" unless you export them.
If you define a variable in child, even if you export it, it won't be seen in the parent after child finishes. This is because the child program runs in a subshell. What you could do is source the child program either like:
source child
or
. child
Now the child program is read in and executed in the same shell instead of a subshell, and the variable is defined.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.