LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 08-20-2009, 02:52 PM   #1
web_janitor
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"
A B C
_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
crabboy
Moderator
 
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
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware, Mint
Posts: 1,240

Rep: Reputation: 196Reputation: 196
Try that command:

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

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


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 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


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