LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 04-05-2012, 03:54 AM   #1
linuxquestions_alex
LQ Newbie
 
Registered: Oct 2011
Posts: 3

Rep: Reputation: Disabled
CSH variable call


Hi all,
I'm in bash, using csh to program.

file name "bbb.csh"
Code:
#! /bin/csh -f
set b1=3
set b2=50
set b=`expr $b1 + $b2`
echo $b
file name "aaa.csh"
Code:
#! /bin/csh -f
./bbb.csh
echo $b
It computes right after %./bbb.csh, but displays "b: Undefined variable" after %./aaa.csh.
How to call variable b in file aaa.csh?
Thanks.

Last edited by linuxquestions_alex; 04-05-2012 at 03:58 AM.
 
Old 04-05-2012, 04:10 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
generally you'd source a script like that, not execute it. This is basically like an "include" function in conventional programming, so doesn't start a new shell, but includes all the commands in the current location:

Code:
. bbb.csh
 
Old 04-05-2012, 04:35 AM   #3
linuxquestions_alex
LQ Newbie
 
Registered: Oct 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Yes, information really helps. Thank you, acid_kewpie.
Could variables be set GLOBAL like some script languages, so the variables are available for other opening shells?
 
Old 04-05-2012, 05:09 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
Variables are never global. They inherit from their parent process. if you have to terminals opened in the same way, from a desktop menu etc, they are isolated from each other and you can't make a shell variable available between them by setting it in one.
 
  


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
csh Shell Script: Getting wc command output to variable to do math on it, how? vxc69 Programming 5 05-04-2009 05:31 PM
Error message on opening up a csh terminal in Fedora 9 Unknown colorls variable `ca'. mrground Linux - Software 3 08-01-2008 12:37 PM
system call as variable RudraB Programming 5 07-09-2008 03:00 AM
csh: variable input of the form x.y.z not accepted kpachopoulos Programming 1 07-24-2005 05:39 PM
how do you set an env variable from within a csh script? BrianK Linux - General 3 05-26-2004 03:16 PM


All times are GMT -5. The time now is 12:05 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration