niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
entires each on separate line
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Wed Jul 19, 2006 11:50 pm    Post subject: Re: entires each on separate line Reply with quote

On 2006-07-19, kevin_m wrote:
Quote:
Hi,
I want to save command output in some variable, for example:
a=`who`
when i print this variable, there are all entries displayed on one
line, but I need each entry on a separate line.
How can I do this?

Presumably, you are using a command like this:

echo $a

When $a is expanded, each white-space-separated word becomes a
separate argument, and echo prints it arguments separated by a
space.

If you want to preserve the formatting of $a, quote it:

echo "$a"

Better still, use printf:

printf "%s\n" "$a"

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
kevin_m
*nix forums beginner


Joined: 14 Jul 2006
Posts: 6

PostPosted: Wed Jul 19, 2006 10:54 pm    Post subject: Re: entires each on separate line Reply with quote

kevin_m napísal(a):
Quote:
Hi,
I want to save command output in some variable, for example:
a=`who`
when i print this variable, there are all entries displayed on one
line, but I need
each entry on a separate line.
How can I do this?

Thanks

I forgot mentioned that I use korn shell
Back to top
kevin_m
*nix forums beginner


Joined: 14 Jul 2006
Posts: 6

PostPosted: Wed Jul 19, 2006 10:51 pm    Post subject: entires each on separate line Reply with quote

Hi,
I want to save command output in some variable, for example:
a=`who`
when i print this variable, there are all entries displayed on one
line, but I need
each entry on a separate line.
How can I do this?

Thanks
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Thu Dec 04, 2008 3:37 am | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts number of words in a line Fred J. C++ 3 Fri Jul 21, 2006 3:52 am
No new posts Connection refused at /usr/lib/perl5/vendor_perl/5.8.6/Ma... DragonsLord Mandrake 0 Thu Jul 20, 2006 12:44 pm
No new posts Questions about "Line too long" Jonas Meurer Exim 9 Wed Jul 19, 2006 5:29 pm
No new posts Bug#378859: ITP: pypar2 -- graphical frontend for the par... Piotr Ozarowski devel 1 Wed Jul 19, 2006 12:00 pm
No new posts how to extract multi-line text perltcl@yahoo.com Perl 2 Wed Jul 19, 2006 4:57 am

Electricity Suppliers | Credit Cards | Duwayne Burnside | Xbox Mod Chip | Loans
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2255s ][ Queries: 20 (0.1564s) ][ GZIP on - Debug on ]