Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 08-20-2009, 02:52 PM   #1
LQ Newbie
Registered: Nov 2008
Location: USA
Distribution: rhell 4/5
Posts: 18

Rep: Reputation: 1
When I use xargs with echo, why does the output contain an extra space?

I have a small puzzler here. I'm trying to create a one-liner, where I am combining the output from two different echo commands. The result is not quite what I expect.

For example, I expect the following command to list both lines aligned. But it does not:

# echo "1 2 3" | xargs echo -e "A B C\n"
_1 2 3

Notice the extra space on the second line (denoted by the "_"). It seems as if xargs adds a space... but why?

(For others having this problem: In order to fix it, I just add the backspace sequence to echo: echo "1 2 3" | xargs echo -e "A B C\n\b" )
Old 08-20-2009, 03:06 PM   #2
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Consider the example:

echo filename | xargs ls

if xargs did not add a space the command would come out as

lsfilename instead of ls filename
Old 08-20-2009, 04:18 PM   #3
Senior Member
Registered: May 2008
Location: Poland
Distribution: Slackware, Mint
Posts: 1,252

Rep: Reputation: 205Reputation: 205Reputation: 205
Try that command:

$ echo "1 2 3" | xargs echo "A B C"
A B C 1 2 3
Here you see why xargs adds a space:

$ echo -n "1 2 3"; echo "A B C"
1 2 3A B C


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
move extra space from one partition to another wit_273 Linux - General 4 05-24-2007 11:57 AM
extra hard disk space ic_torres Linux - Hardware 7 11-03-2005 07:56 PM
need to mount extra / space Geist3 Slackware 5 01-17-2005 08:31 PM
Install XP in extra space jdmml Linux - Newbie 4 08-31-2004 01:42 PM
extra hd space? adam_boz Linux - Newbie 2 10-24-2002 02:08 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:28 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration