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.
|
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 |
[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 |
[QUOTE=earthdog;3791607]
Quote:
|
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 :) |
Quote:
Earthdog |
Quote:
|
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. |
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. |
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. |