![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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 !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assigning output of a command to variable | jeriryan87 | Shell Programming and Scripting | 9 | 06-30-2008 05:55 PM |
| Assigning output to a variable | jpmena | Shell Programming and Scripting | 3 | 03-27-2008 04:39 AM |
| Assigning output of command to a variable in shell | sankar reddy | Shell Programming and Scripting | 6 | 02-28-2008 03:01 AM |
| assigning command output to a shell variable | kprattip | Shell Programming and Scripting | 2 | 07-09-2007 05:01 AM |
| Assigning output of command to a variable | oma04 | Shell Programming and Scripting | 5 | 06-27-2006 01:11 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
|||||
|
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 62832
Note 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.) |
|
||||
|
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. |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|