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.
[ec2-user@Splunk-Server ~]$ test=a
[ec2-user@Splunk-Server ~]$ echo $test
a
[ec2-user@Splunk-Server ~]$ export test --> Exported a variable
[ec2-user@Splunk-Server ~]$
[ec2-user@Splunk-Server ~]$
[ec2-user@Splunk-Server ~]$ sudo su - --> I changed to root login.
Last login: Thu Jan 19 22:07:26 UTC 2017 on pts/0
[root@Splunk-Server ~]# echo $test
[root@Splunk-Server ~]#
I can't get that variable in root login though I exported that variable.
Hi All,
I was trying to learn how export command works. I tried to export a vaiable as show below:
[ec2-user@Splunk-Server ~]$ test=a
[ec2-user@Splunk-Server ~]$ echo $test
a
[ec2-user@Splunk-Server ~]$ export test --> Exported a variable
[ec2-user@Splunk-Server ~]$
[ec2-user@Splunk-Server ~]$
[ec2-user@Splunk-Server ~]$ sudo su - --> I changed to root login.
Last login: Thu Jan 19 22:07:26 UTC 2017 on pts/0
[root@Splunk-Server ~]# echo $test
[root@Splunk-Server ~]#
I can't get that variable in root login though I exported that variable. Am I missing something here?
Aside from the very obvious "you changed user ID's and the variable was only exported to ec2-user"? No....
When you change users, the variables you assign to a user stay with that user. When you started a new root shell, those variables don't apply unless you set them in the root .profile/.bash_rc or in the default /etc/profile.
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 3,096
Rep:
also the op should be made aware that the exported vars go down the chain and not up, eg if you export a variable any child process created will have acces to it but parent processes will not, you cant for instance export a variable to a child process, have that child process alter the variable and then export it back up to the parent process.
Which is a bit of a 'gotcha' when using pipes, got me when I was learning anyway!
Last edited by Keith Hedger; 01-19-2017 at 07:17 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.