LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 03-21-2009, 09:37 AM   #1
virteman
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Rep: Reputation: 0
Question Can xargs's initial-arguments expand?


hello, why can't the xargs's intial-arguments which are passed to any command expanded?

First I Can list the file with a wild expansion.

Code:
virteman@ubuntu:/tmp$ ls -l tmp* 
-rw------- 1 root root 0 2009-03-21 18:50 tmp.yWkOcZ6220
Second I echo the wild expansion pipe to xargs and then list it. But the exception occur to here.

Code:
virteman@ubuntu:/tmp$ echo 'tmp*' |xargs -t ls -l
ls -l tmp* 
ls: cannot access tmp*: No such file or directory
Then I add bash -c to the list command , And it seams OK.

Code:
virteman@ubuntu:/tmp$ echo 'tmp*' |xargs -t -I{}  bash -c 'ls -l {}'
bash -c ls -l tmp* 
-rw------- 1 root root 0 2009-03-21 18:50 tmp.yWkOcZ6220
I want to know why I cannot use the second command?
 
Old 03-22-2009, 04:49 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

If you remove the quotes it works:

Quote:
touch tmp.yWkOcZ6220

ls -l tmp*
-rw-r----- 1 druuna internet 0 Mar 22 10:45 tmp.yWkOcZ6220

echo tmp* | xargs ls -l
-rw-r----- 1 druuna internet 0 Mar 22 10:45 tmp.yWkOcZ6220

echo 'tmp*' | xargs ls -l
ls: tmp*: No such file or directory

echo "tmp*" | xargs ls -l
ls: tmp*: No such file or directory
Without the quotes bash will expand the tmp* part first before giving it to echo, the other 2 (with the double/single quotes) prohibit bash from expanding and tmp* is echoed as is.

Hope this clears things up a bit
 
Old 03-25-2009, 03:58 AM   #3
virteman
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Wink

Quote:
Originally Posted by druuna View Post
Hi,

If you remove the quotes it works:



Without the quotes bash will expand the tmp* part first before giving it to echo, the other 2 (with the double/single quotes) prohibit bash from expanding and tmp* is echoed as is.

Hope this clears things up a bit
yes, of course,it works. In fact I want to xargs pass "tmp*" this expression to its later call command , and then the command can let bash expand "tmp*", at last the command can run with the arguments as it runs in a common command line .
 
  


Reply

Tags
xargs



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
Expand partition on system in use SyCo123 Linux - General 5 11-26-2008 11:53 AM
Amarok - expand all? Changes Linux - Software 0 10-27-2008 08:10 PM
expand LVM madunix Linux - General 5 11-13-2007 09:03 AM
ntfs expand edgefield Linux - General 6 10-23-2004 09:28 PM
Need to expand /usr partition marenkiapina Linux - Software 2 05-22-2004 06:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:41 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration