LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how can i create a global variable called "dogpatch" with a value of "woof" (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-create-a-global-variable-called-dogpatch-with-a-value-of-woof-775666/)

earthdog 12-14-2009 07:14 PM

how can i create a global variable called "dogpatch" with a value of "woof"
 
how do i create a global variable called "dogpatch" with a value of "woof" (in red hat, I am new at this and am trying to figure it out but i need help.

GrapefruiTgirl 12-14-2009 07:16 PM

Hi, welcome to LQ :)

You must tell us what language you're writing your code in, as there's likely going to be some semantic and syntactic differences from language to language.

Sasha

earthdog 12-14-2009 07:33 PM

[QUOTE=earthdog;3791589]how do i create a global variable called "dogpatch" with a value of "woof" (in red hat, I am new at this and am trying to figure it out but i need help.[/QUOT
i am writing my code in english

earthdog

earthdog 12-14-2009 07:41 PM

[QUOTE=earthdog;3791607]
Quote:

Originally Posted by earthdog (Post 3791589)
how do i create a global variable called "dogpatch" with a value of "woof" (in red hat, I am new at this and am trying to figure it out but i need help.[/QUOT
i am writing my code in english

earthdog

i am writing my code in linux

chrism01 12-14-2009 07:49 PM

Linux is not a language, it's an OS. The qn is which programming language eg do you mean bash (aka shell script)?
If so,

dogpatch=woof

note we don't put spaces around the '=', that's important. To retrieve the value you prefix the var name with '$' eg

echo $dogpatch

See these tutorials:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

HTH
Welcome to LQ
:)

earthdog 12-14-2009 07:53 PM

Quote:

Originally Posted by chrism01 (Post 3791622)
Linux is not a language, it's an OS. The qn is which programming language eg do you mean bash (aka shell script)?
If so,

dogpatch=woof

note we don't put spaces around the '=', that's important. To retrieve the value you prefix the var name with '$' eg

echo $dogpatch

See these tutorials:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

HTH
Welcome to LQ
:)

right on, Im using the Korn shell
Earthdog

earthdog 12-14-2009 07:56 PM

Quote:

Originally Posted by earthdog (Post 3791628)
right on, Im using the Korn shell
Earthdog

I get it know thanks chrism01

chrism01 12-14-2009 09:45 PM

Well, korn is highly compatible with bash, but see http://kornshell.com/ for more ksh docs than you ever wanted :)
Also, please click the Blue Thumbs-up on someone's post to thank them as well.

evo2 12-14-2009 09:50 PM

The term "global variable" has a specific meaning in programing: I suspect what you are trying to do with ksh, is actually something a little different, since usually in shell scripts all variables are global. So, can you tell us what you are actually trying to achieve?

Evo2.

chrism01 12-15-2009 01:03 AM

Seeing as we've established ksh (yes ?), the nearest thing to a 'global' var is to 'export' it.
A var set/declared in a given shell level is avail to the code at that level.
You can export it, but this only makes it available to any sub-shells called from the current env. You cannot export (or 'return') a var upwards in the shell tree.

This is true of shell scripting generally ie bash, ksh, sh etc.
See the docs I linked to.


All times are GMT -5. The time now is 10:46 AM.