Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-23-2006, 03:27 PM   #1
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
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)
FIRST=$(ls -l | head -1)
Old 03-23-2006, 03:30 PM   #3
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,138

Rep: Reputation: 166Reputation: 166
FIRST=`ls -l | head -1`
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.


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 > Forums > Linux Forums > Linux - Newbie

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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration