simple question about bash .. ls and rm combination
hi guys < and ladies of course, if there is :) > <please don't, i'm just kidding >
my name is Özgür from Turkey (Türkiye) .. here is my information <if necessary> Code:
[root@redwin test2]# cat /etc/*-release Code:
[root@redwin test2]# bash --version why can't i use "ls" with "rm" .. please check out this work .. (i've just prepared easy example) Code:
[root@redwin test2]# touch file{1,2,3,4,5,6,7,8,9} thanks .. |
For a pipe to work the item you're piping into has to accept stdin as input but it doesn't - it requires a definite target.
However you can use the xargs command for this purpose - for each input from a pipe it repeats the command using the input as the target: ls -1 file* |xargs rm -rf It isn't clear why you'd do this though since you could more easily simply type: rm -rf file* |
The pipe sends the output of one command to the input of the other. To use the output of one command as the command line arguments for another, use backquotes.
Rather than ls and rm, lets use foo and bar so it doesn't look silly. Quote:
Hope this helps, Phil |
thanks
thank you for your explanation :) i think, that's the why xargs command's existance :) for first look, it seems really silly or non logical to me .. thank you again ..
by the way, of course i could (rm -rf file*) :) i was just trying different pipe methods :) is it clear now ? :) Quote:
|
Quote:
|
Quote:
Phil |
Quote:
|
Quote:
|
I know the feeling; I still use `...` for simple ones
|
Quote:
I deprecate Fortran, but that ain't slowing the M&S crowd down. |
I used the word "deprecated" rather than "forbidden".
As for me I like to prove that you CAN teach old dogs new tricks. Having seen two separate shell scripting presentation in recent months where the presenters made cogent arguments for use of $() (including that it works in ksh which was important to me) was good enough for me to try to start changing the habit. The cut command still exists and though I used it in several of my early scripts years ago for field separation I almost always use awk instead these days. Nowadays I typically use it mainly for character splits rather than field splits. |
All times are GMT -5. The time now is 06:54 AM. |