|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
assigning (numeric) command output to var tcsh
Hello,
I'm trying to assign a numeric value that is returned from one of my programs to a variable in tcsh. I want to do: @ r10 = './my_prog file 35' where ./my_prog file 35 returns a decimal value, but this doesn't work. How do I achieve the desired result? Janet |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
What you are asking is for a child (called) process to return info to parent (master) program. The construct of unix does not allow for this as whatever is learned by the child does not have a way to naturally pass to parent; the reverse is ok, and is often accomplished with an EXPORT command.
Searching this forum will probably provide several creative solutions. Some are: (a) return the value by way of the exit error parameter of the child back to the parent (b) have the child write the data to a temporary file that the parent can then read |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Hi. Keeping in mind that: Quote:
Code:
#!/usr/bin/env tcsh @ result = 31416 * 2 echo $result exit As a source to set a variable in a larger script: Code:
#!/usr/bin/env tcsh # @(#) s1 Demonstrate script result capture. echo echo "(Versions displayed with local utility version)" sh -c "version >/dev/null 2>&1" && version tcsh echo echo " Nonce script:" cat -n t1 echo echo " Results:" set var1 = `./t1` echo " var1 is $var1" exit 0 Producing: Code:
% ./s1
(Versions displayed with local utility version)
tcsh 6.13.00
Nonce script:
1 #!/usr/bin/env tcsh
2
3 @ result = 31416 * 2
4 echo $result
5
6 exit
Results:
var1 is 62832Note that the odd quotes (`) are backtics, not straight single quotes. See the man page for other details ... cheers, drl (The usual advice advocating the use of Bourne family shells as opposed to csh family applies here.) |
|
#4
|
|||
|
|||
|
If by "returned" you mean "written to standard output", then simply use backticks to capture the output of my_prog: Code:
@ r10 = `./my_prog file 35` Note that a tcsh @ variable must be assigned an integer value. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thanks folks...
Thanks for the really helpful posts.
A combination of writing only ints to standard output from my program and the use of backtics has cracked my problem. Thanks for spending the time to explain & provide a solution too - much appreciated. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assigning expression value to tcsh variables | AB10 | Shell Programming and Scripting | 2 | 10-19-2010 07:33 AM |
| Assigning output of a command to variable | jeriryan87 | Shell Programming and Scripting | 9 | 06-30-2008 04:55 PM |
| Assigning output of command to a variable in shell | sankar reddy | Shell Programming and Scripting | 6 | 02-28-2008 02:01 AM |
| assigning command output to a shell variable | kprattip | Shell Programming and Scripting | 2 | 07-09-2007 04:01 AM |
| Assigning output of command to a variable | oma04 | Shell Programming and Scripting | 5 | 06-27-2006 12:11 PM |
|
|