LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-11-2008, 06:22 PM   #1
stabu
Member
 
Registered: Mar 2004
Location: dublin IRL
Distribution: Slackv12.1, Slamd64v12.1,Xubuntu v8.10_64, FC8_64
Posts: 438
Blog Entries: 5

Rep: Reputation: 31
bash:redirection to a variable, not file


Hi,
I have a compiled c program that prints out a number. I want to write a bash script that collects that number into a variable (ok, it will be an array, in a loop, but that doesn't matter).
Code:
variable = $(myprog myarg)
was the way I thought it could do it. But doesn't work.
Of course I can redirect the output to a file and then read from the file, but that's messy. That's what bash redirections are for, really.
I also can modify my program to make it return the value rather than print it, but I was hoping to do this in bash.
My searching for this has not come up trumps yet.
Cheers for advice.
 
Old 08-11-2008, 06:25 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
When you're doing assignment in bash, no spaces around the '=' does the trick.
An exception to the usual rule of not doing that eg in if statements etc.
 
Old 08-11-2008, 06:40 PM   #3
stabu
Member
 
Registered: Mar 2004
Location: dublin IRL
Distribution: Slackv12.1, Slamd64v12.1,Xubuntu v8.10_64, FC8_64
Posts: 438
Blog Entries: 5

Original Poster
Rep: Reputation: 31
hi chrism01

Yaggg! You beat me to it, I had just done some more fiddling in vim, and by mistake, I didn't put a space and hey presto, syntax highlighting kicked in vim! So I came back here to retract it all!

Actually I've noticed this before in bash ... in the test statement [ has to have a space on either side, no?

These seem to be quite weird (and somewhat inconsistent) syntax convention. Bash has dark corners though, it's known ...

Thanks for the fast reply!
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting a variable from a text-file (bash) PatrickBecks Programming 4 02-14-2008 08:52 PM
BASH writing from variable to file Planescape Programming 6 01-11-2007 10:41 AM
Variable in Bash get from other file?? helptonewbie Programming 4 08-21-2006 07:51 AM
BASH scripting: confused about redirection & file descriptors funkymunky Programming 1 06-07-2004 07:47 AM
Bash - Using variable from a .conf file steevy18 Programming 1 10-28-2003 11:58 AM


All times are GMT -5. The time now is 11:09 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
Open Source Consulting | Domain Registration