Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Scripting Issues...

0 views
Skip to first unread message

Ramon

unread,
Nov 21, 2009, 11:44:19 AM11/21/09
to
Hi,

My problem is that my script cannot access variables that are stored in
~/.bashrc.

Here is (part of) my local .bashrc file:
$ cat ~/.bashrc
myvar="abc"

And here is my small script:
$ cat myscript.sh
#!/bin/bash
echo "$myvar"

The $myvar is loaded correctly:
$ echo $myvar
abc

But the script is unable to display it...
$./myscript.sh
$

For some reason nothing is displayed when I execute myscript.sh. Is
there a solution for this problem?

Ramon.

Robert Newson

unread,
Nov 21, 2009, 12:13:31 PM11/21/09
to
Ramon wrote:
> Hi,
>
> My problem is that my script cannot access variables that are stored in
> ~/.bashrc.
>
> Here is (part of) my local .bashrc file:
> $ cat ~/.bashrc
> myvar="abc"
Try:

export myvar="abc"

instead
...


> For some reason nothing is displayed when I execute myscript.sh.

myvar is [a] local [variable] to the running bash and not part of its
environment variables which are "exported" to any new program.


> Is
> there a solution for this problem?

See above.

J.O. Aho

unread,
Nov 21, 2009, 12:14:04 PM11/21/09
to
Ramon wrote:
> Hi,
>
> My problem is that my script cannot access variables that are stored in
> ~/.bashrc.
>
> Here is (part of) my local .bashrc file:
> $ cat ~/.bashrc
> myvar="abc"

That is a local variable, you need to export the variable to other processes-


export myvar="abc"

Test your script after that.

--

//Aho

Ramon

unread,
Nov 21, 2009, 12:27:38 PM11/21/09
to

Thx lads, it worked great.

Jon Solberg

unread,
Nov 21, 2009, 1:18:07 PM11/21/09
to
["Followup-To:"-huvud satt till alt.os.linux.ubuntu.]

On 2009-11-21, Ramon <ramif_47...@yahoo.co.uk> wrote:
> Ramon wrote:
>> Hi,
>>
>> My problem is that my script cannot access variables that are stored in
>> ~/.bashrc. [...]

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html may prove useful for
you.

--
Jon Solberg (remove "nospam." from email address).

0 new messages