LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-14-2009, 07:14 PM   #1
earthdog
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Rep: Reputation: 0
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.
 
Old 12-14-2009, 07:16 PM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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
 
Old 12-14-2009, 07:33 PM   #3
earthdog
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
[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
 
Old 12-14-2009, 07:41 PM   #4
earthdog
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
[QUOTE=earthdog;3791607]
Quote:
Originally Posted by earthdog View Post
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
 
Old 12-14-2009, 07:49 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,283

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
Old 12-14-2009, 07:53 PM   #6
earthdog
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
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
 
Old 12-14-2009, 07:56 PM   #7
earthdog
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by earthdog View Post
right on, Im using the Korn shell
Earthdog
I get it know thanks chrism01
 
Old 12-14-2009, 09:45 PM   #8
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,283

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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.
 
Old 12-14-2009, 09:50 PM   #9
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,377

Rep: Reputation: 1173Reputation: 1173Reputation: 1173Reputation: 1173Reputation: 1173Reputation: 1173Reputation: 1173Reputation: 1173Reputation: 1173
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.
 
Old 12-15-2009, 01:03 AM   #10
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,283

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the "data type" of an "unknown variable" in "C Language" ? Affair Programming 8 06-20-2009 12:30 PM
ACPI S3 (so-called "Standby" or "Sleep") in GNU/Linux posix_memalign Linux - Laptop and Netbook 1 01-17-2009 01:54 PM
c++ - "index" is a global scope variable in <string>???? BrianK Programming 2 03-18-2008 08:05 PM
I hate to be called a "CODER", "PROGRAMMER"...when.. StevenO General 5 08-01-2007 03:34 PM
"Broken" envirnment variable (MANPATH) and "/etc/profile.d" question. ErV Slackware 3 03-20-2007 09:42 AM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration