Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 11-02-2007, 11:50 PM   #1
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:

echo -n "148" > A
echo -n "148" > A=
echo -n "148" | A
echo -n "148" | A=
echo -n "148" |  read A
Old 11-03-2007, 12:22 AM   #2
Registered: May 2007
Posts: 208

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

Original Poster
Rep: Reputation: 0
Tks a lot, it works.
Old 11-04-2007, 07:01 AM   #4
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

(where the ` are french accents grÔve, not apostrophies.)
Old 11-04-2007, 11:53 AM   #5
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.



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

All times are GMT -5. The time now is 04:38 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration