LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 03-23-2006, 03:27 PM   #1
true_atlantis
Member
 
Registered: Oct 2003
Distribution: fedora cor 5 x86_64
Posts: 639

Rep: Reputation: 30
set the ouput of a command to a variable


how do i set the output of a command to a variable? for example,

ls -l | head -1

i want the output of that to be in varible $FIRST. how would i do that?

FIRST=ls -l | head -1

does not work...
 
Old 03-23-2006, 03:29 PM   #2
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
FIRST=`ls -l | head -1`
(back quotes and not quotes)
or
FIRST=$(ls -l | head -1)
 
Old 03-23-2006, 03:30 PM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 151Reputation: 151
Try:
Code:
FIRST=`ls -l | head -1`
Or:
Code:
FIRST=$(ls -l | head -1)
That should do it.

Oops - looks like I was too slow, again

Last edited by gilead; 03-23-2006 at 03:31 PM.
 
  


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
How to set PATH variable for command tracert? princegbenga Linux - Software 2 06-14-2007 07:48 AM
how to set $PATH variable definitely unihiekka Linux - Software 2 12-15-2005 10:12 AM
How to set a value of environment variable? ukrainet Linux - Newbie 1 12-28-2004 04:33 AM
Set variable with value of another Ephracis Programming 7 12-25-2004 10:34 AM
How to set a environment variable in rh? yenonn Linux - Newbie 11 02-21-2003 10:24 PM


All times are GMT -5. The time now is 11:54 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