LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 10-03-2011, 09:32 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,655

Rep: Reputation: 51
How do I make a script to export its variables to the invoking shell?


Kernel 2.6.21.5, slackware 12.0

Hi:
Code:
$ cat s1
#!/bin/sh

JOHN=123
export JOHN
$ ./s1
$ echo $JOHN

$
I expected echo to print "123". By looking at a post, I saw that
Code:
$ source s1
behaves as expected. Now the problem is another. I have /etc/rc.d/rc.local. This file (bash script) runs at boot. Within it I want to write, suppose, JOHN=ABC. How do I do to have JOHN hold its value after I login?
 
Old 10-03-2011, 09:50 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
export JOHN=123
 
Old 10-03-2011, 10:21 AM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,655

Original Poster
Rep: Reputation: 51
Thanks very much. But what if I write

alias JACK=ls

in rc.local? Because I never could make it work.
 
Old 10-03-2011, 11:01 AM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
alias JACK="ls"
 
Old 10-04-2011, 04:33 AM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,655

Original Poster
Rep: Reputation: 51
sorry, I meant

alias JACK="ls"

Last edited by stf92; 10-04-2011 at 04:34 AM.
 
Old 10-05-2011, 06:37 AM   #6
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
Im not certain rc.local is where alias' should go..
Ive always put them in ~/.bashrc

or /etc/bashrc, where it should be called by each users .bashrc
 
Old 10-05-2011, 09:57 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
rc.local is run by root as last part of boot.
If you want to be able to sue a value generated there, you'll have to write it to a file and read it back when you login.

Quoting my .bashrc
Code:
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
which is the default install version. As hinted, personal aliases should go at the end of that file.
You may or may not know that 'ls' doesn't show files beginning with '.'; use 'ls -a' to see them.

HTH
 
Old 10-06-2011, 08:25 AM   #8
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,655

Original Poster
Rep: Reputation: 51
Thank you very much. I have another question, which is in fact a reiteration of post #1: when the booting process ends and after I login, the program who reads input from the console is bash. This instance of bash I'll call it instance_1. Now I run sample.sh.

$ cat sample.sh
#!/bin/sh
export JACK=123
$

And then

$ echo $JACK

$

A new instance of bash executed the export sentence, say instance_2. But JACK was not exported to the environment of instance_1. Where was it exported to?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
invoking windows command inside a shell script nano2 Programming 6 09-09-2009 04:46 AM
Invoking a shell script remotely. niks27 Linux - Newbie 1 10-11-2007 08:22 AM
bash script--variables have unexpected values on invoking mplayer stairwayoflight Programming 5 07-08-2007 12:17 PM
How can I export my variables from a script? HGeneAnthony Debian 2 05-20-2006 05:47 PM
Unable to export variables declared in a script joehansen12 Linux - Newbie 2 10-26-2005 03:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration