[Asterisk-Dev] bash export

Dermot McGahon dermot at dspsrv.com
Fri Apr 16 08:07:08 MST 2004


> The new question is: suppose "export
> LD_ASSUME_KERNEL=2.4.1" is issued inside the script
> that starts safe_asterisk, if I stop and start Asterisk
> manually, inside a bash session, what happens to this
> variable? Do I have to write a script that always
> includes this variable before I restart asterisk? is it
> better to somehow include this environment variable in
> the C code? How? Sorry for being new to Linux.

From: man bash

        export [-fn] [name[=word]] ...
        export -p
               The  supplied names are marked for automatic export to the 
envi-
               ronment of subsequently executed commands.  If the -f 
option  is
               given,  the names refer to functions.  If no names are 
given, or
               if the -p option is supplied, a  list  of  all  names  that  
are
               exported  in  this  shell  is printed.  The -n option causes 
the
               export property to be removed from the named variables.   
export
               returns  an exit status of 0 unless an invalid option is 
encoun-
               tered, one of the names is not a valid shell variable  
name,  or
               -f is supplied with a name that is not a function.

As with some unix manpages when you're a beginner, this may not be getting
across to you what you need to know, even though what you need to know, is
stated. And there is a lot to get to know. Make an effort, be seen to make
an effort, but most importantly, read carefully and follow any advice you
are given on lists such as this and you should learn quickly.

Forget about C code. It's an environment variable, controlled by shell
built-in commands. It can be set by a C program but irrelevant for what
you need.

To see the current value of the variable, do:

$ echo $LD_ASSUME_KERNEL

If it's not currently set, you need to set it. Any command in a script
can also be typed in directly at the shell. So do:

$ export LD_ASSUME_KERNEL=2.4.1

The export makes sure that this variable is among the variables set up
in any sub-shells of your current shell. Just:

$ LD_ASSUME_KERNEL=2.4.1

will set the variable in your current shell, but to see why this won't
work, do:

$ bash
$ echo LD_ASSUME_KERNEL

It won't be there because it wasn't exported in the parent shell. When
you run certain scripts, with #!/bin/bash at the top of them for example,
you are telling the command interpreter basically to execute these
commands in a new shell. Do:

$ ps aux | grep bash

and you will see that you can have many shells, not just one.

That should get you going. BTW, this is off-topic for this newsgroup so
you'll have to excuse people for rightly telling you so, and I hope people
won't be mad with me for taking five minutes to explain a few basics to
somebody who seems genuine enough even though I realise that also makes me
off-topic!

To see the value of all variables in the current shell, type:

$ set

If it scrolls off the page, try:

$ set | less


One other thing. Change the subject line before posting to something which
explains the, well, subject. You are replying to digest emails which don't
identify the subject sufficiently well.


Dermot.
--



More information about the asterisk-dev mailing list