[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Weird behavior for a bash script



Ibrahim Mubarak <ibmub80@yahoo.com> writes:

> Hi all,
>
> I am trying to create a very basic script that exports a global path variable.
> I know I can include the export statement in my .bashrc file, but I don't want this variable set
> unless I have to have it set. I guess I am hardheaded!
>
> I can't get it to work.
>
> Here is my script:
> [QUOTE]
> #!/bin/bash
> export PKG_CONFIG_PATH='/usr/local/lib/pkgconfig':$PKG_CONFIG_PATH
> echo $PKG_CONFIG_PATH
>
> [/QUOTE]
>
> That's it. I did make it executable. When I run it, i get this:
>
> [QUOTE]
> ib:~$ ./beforeMaking.sh
> /usr/local/lib/pkgconfig:
> ib:~$ echo $PKG_CONFIG_PATH
>
> ib:~$
> [/QUOTE]
> As you can see, the path is set in the script, but outside of it, still not changed.
> What am I doing wrong? Did I miss something?

You need to source the script, not to execute it:

. ./beforeMaking.sh

Sourcing it will be executed in your current shell (and export will
therefore work), if you execute it, it will be executed in a child process
and once the child is gone, its exports are gone as well.

Do you really want to have '/usr/local/lib/pkgconfig' in the script? I
would expect that to be `/usr/local/lib/pkgconfig`

Dragan

-- 
Dragan Cvetkovic, 

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!



Reply to: