LinuxQuestions.org
Help answer threads with 0 replies.
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
 
Search this Thread
Old 11-03-2007, 12:50 AM   #1
poincare999
LQ Newbie
 
Registered: Sep 2007
Posts: 6

Rep: Reputation: 0
Script: put the output of a command into a variable.


I want the output of command1 goes into variable A .
For instance, if command1 = echo -n "148" , I want put 148 into A .

I have done some tries, but these doesn't work:

Code:
echo -n "148" > A
echo -n "148" > A=
echo -n "148" | A
echo -n "148" | A=
echo -n "148" |  read A
....etc
Tks
 
Old 11-03-2007, 01:22 AM   #2
ocicat
Member
 
Registered: May 2007
Posts: 208

Rep: Reputation: 47
Quote:
Originally Posted by poincare999 View Post
I want the output of command1 goes into variable A .
Code:
#!/bin/sh
a=$(echo -n '148')
echo $a
 
Old 11-03-2007, 01:43 AM   #3
poincare999
LQ Newbie
 
Registered: Sep 2007
Posts: 6

Original Poster
Rep: Reputation: 0
Tks a lot, it works.
 
Old 11-04-2007, 08:01 AM   #4
doc.nice
Member
 
Registered: Oct 2004
Location: Germany
Distribution: Debian
Posts: 274

Rep: Reputation: 34
Next time, you may try searching the net or this forum, this question is very common.
When you provide more information, such as the script LANGUAGE you are using, you will get better results.

another way that would work in bash/ash/tcsh/... is
varname=`command`

(where the ` are french accents grÔve, not apostrophies.)
 
Old 11-04-2007, 12:53 PM   #5
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
The ` are also known as backticks. in bash the construct $( ) can be used in place of backticks, with the added advantage that the newer construct can be nested.

If you fail to learn something new here every day, check, because you may have died and just not realised it.


PAix
 
  


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
Write output or command to variable (shell) kernel_geek Programming 9 03-12-2007 05:45 AM
how to save output from a command to a variable? tomolesonjr Linux - Newbie 6 04-19-2006 04:04 PM
passing command output to variable Infernal211283 Linux - Newbie 12 01-11-2006 06:54 AM
Odd problem with making a variable the output of a command in a shell script linux=future Programming 3 12-13-2005 10:45 PM
Can I put execl command output into a file? CrazyDragon Programming 1 12-17-2003 05:34 AM


All times are GMT -5. The time now is 06:29 PM.

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