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 have some 10 environment variables that I repeatedly need to export, every time I need to do something. And typing 'export varname' ten times for each session is rather tedious. So I put those in a file abc.sh and changed mode to 777 to execute. But after I execute that shell script, the variables don't seem to have exported (when I do 'env | grep VARNAME).
Is it possible to export vars from shell script. If so, how?
Thanks in advance.
Also, as a side question, how to find (from terminal) if this is a redhat or a fedora or debian or any other distro? I did uname -a, and it doesn't mention distro name except the kernel version.
When you export variables their value applies to the shell that does the export and all subshells. They do not apply to the parent shell. When you issue the command a subshell executes the command. The variables are set for the subshell and then lost when the subshell exits back to the shell where you issued the command.
To set the environmental variables for your shell put the export commands in /home/user/.bashrc or /home/user/.profile or home/user/.bash_profile, whichever your distribution uses.
If you execute it all is done in a new shell, once the program is finished that shell is closed and all settings are 'lost'. When you parse a file, all is done in the current shell (the one you typed the command in).
Parsing: . file (that's a dot followed by a space followed by the filename).
You also don't need the execute permissions when you parse, 644 (or better 640) is enough.
About the other question: Most distro's create a file in /etc that has the word release in it. It will contain some distro related info.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.