yes with xargs - Unix

This is a discussion on yes with xargs - Unix ; hi, how to use "yes" command with xargs; I tried the following but it's not working. yes | xargs "my stuff" thanks...

+ Reply to Thread
Results 1 to 10 of 10

Thread: yes with xargs

  1. yes with xargs

    hi,
    how to use "yes" command with xargs; I tried the following but it's
    not working.

    yes | xargs "my stuff"

    thanks

  2. Re: yes with xargs

    In article <2571580d-4254-43c3-8f1d-940fb3d7d0c0@u57g2000hsf.googlegroups.com>,
    sinbad wrote:
    >hi,
    >how to use "yes" command with xargs; I tried the following but it's
    >not working.
    >
    >yes | xargs "my stuff"


    I tried that here and it's doing exactly what I expected it to.

    What are you Really Trying To Do?


    dave

    --
    Dave Vandervies dj3vande at eskimo dot com
    That is a politically unacceptable statement. It shows far too much
    observation of reality and scientific analysis.
    --Nick Maclaren in comp.arch

  3. Re: yes with xargs

    On Oct 20, 8:37*am, dj3va...@csclub.uwaterloo.ca.invalid wrote:
    > In article <2571580d-4254-43c3-8f1d-940fb3d7d...@u57g2000hsf.googlegroups..com>,
    >
    > sinbad * wrote:
    > >hi,
    > >how to use "yes" command with xargs; I tried the following but it's
    > >not working.

    >
    > >yes | xargs "my stuff"

    >
    > I tried that here and it's doing exactly what I expected it to.
    >
    > What are you Really Trying To Do?
    >
    > dave
    >
    > --
    > Dave Vandervies * * * * * * * * * * * * * dj3vande at eskimo dot com
    > That is a politically unacceptable statement. *It shows far too much
    > observation of reality and scientific analysis.
    > * * * * * * * * * * * * * * * * * * * * --Nick Maclaren in comp.arch



    I apolize, actullay i was trying the following

    showcheckout --> it lists all checkout files, Now for each of the
    file, I need to some operation, This operations ask for Yes/No Q;
    so i tried the following, both didn't work

    # showcheckout | yes| xargs -n1 "some operation"
    # showcheckout | xargs -n1 "some operation" | yes

    thanks



  4. Re: yes with xargs

    sinbad writes:

    > On Oct 20, 8:37*am, dj3va...@csclub.uwaterloo.ca.invalid wrote:
    >> In article <2571580d-4254-43c3-8f1d-940fb3d7d...@u57g2000hsf.googlegroups.com>,
    >>
    >> sinbad * wrote:
    >> >hi,
    >> >how to use "yes" command with xargs; I tried the following but it's
    >> >not working.

    >>
    >> >yes | xargs "my stuff"

    >>
    >> I tried that here and it's doing exactly what I expected it to.
    >>
    >> What are you Really Trying To Do?

    >
    > I apolize, actullay i was trying the following
    >
    > showcheckout --> it lists all checkout files, Now for each of the
    > file, I need to some operation, This operations ask for Yes/No Q;
    > so i tried the following, both didn't work
    >
    > # showcheckout | yes| xargs -n1 "some operation"


    This pipes the output of showcheckout into the input of yes (which is
    not going to read it), and the output of yes into 'xargs -n1 "some
    operation". The result would be that showcheckout will hang, trying to
    write output that nobody is reading, and the command

    "some operation" y

    will be run repeatedly until forcibly stopped.

    > # showcheckout | xargs -n1 "some operation" | yes


    This will run "some operation" many times, each time with a command-line
    argument that's a word from the output of "showcheckout". The output of
    these commands gets piped into yes, which won't read it, so the commands
    will hang after a while. Meanwhile the yes command will fill your
    screen with the letter 'y'.

    I think what you want is

    yes | showcheckout

    This sends the output of yes into the input of showcheckout, which is
    likely where it expects to get the answers to its prompts. So it should
    have the effect of answering "y" to every question.

    xargs is useful when you need to use a file or the output of a command
    as *command line arguments* to another command. I don't think that's
    what you're looking for here.

  5. Re: yes with xargs

    On Oct 20, 10:42*am, Nate Eldredge wrote:
    > sinbad writes:
    > > On Oct 20, 8:37*am, dj3va...@csclub.uwaterloo.ca.invalid wrote:
    > >> In article <2571580d-4254-43c3-8f1d-940fb3d7d...@u57g2000hsf.googlegroups.com>,

    >
    > >> sinbad * wrote:
    > >> >hi,
    > >> >how to use "yes" command with xargs; I tried the following but it's
    > >> >not working.

    >
    > >> >yes | xargs "my stuff"

    >
    > >> I tried that here and it's doing exactly what I expected it to.

    >
    > >> What are you Really Trying To Do?

    >
    > > I apolize, actullay i was trying the following

    >
    > > showcheckout *--> it lists all checkout files, Now for each of the
    > > file, I need to some operation, This operations ask for Yes/No Q;
    > > so i tried the following, both didn't work

    >
    > > # showcheckout | yes| xargs -n1 "some operation"

    >
    > This pipes the output of showcheckout into the input of yes (which is
    > not going to read it), and the output of yes into 'xargs -n1 "some
    > operation". *The result would be that showcheckout will hang, trying to
    > write output that nobody is reading, and the command
    >
    > "some operation" y
    >
    > will be run repeatedly until forcibly stopped.
    >
    > > # showcheckout | xargs -n1 "some operation" | yes

    >
    > This will run "some operation" many times, each time with a command-line
    > argument that's a word from the output of "showcheckout". *The output of
    > these commands gets piped into yes, which won't read it, so the commands
    > will hang after a while. *Meanwhile the yes command will fill your
    > screen with the letter 'y'.
    >
    > I think what you want is
    >
    > yes | showcheckout
    >
    > This sends the output of yes into the input of showcheckout, which is
    > likely where it expects to get the answers to its prompts. *So it should
    > have the effect of answering "y" to every question.
    >
    > xargs is useful when you need to use a file or the output of a command
    > as *command line arguments* to another command. *I don't think that's
    > what you're looking for here.


    No that's not what i am looking for
    # showcheckout | xargs -n1 "some operation" | yes

    Here the "some operation" is going to ask a question,not the
    showcheckout, for which i have to answer yes.
    showcheckout simply lists the files, which have to be fed as input for
    "some operation" which will actaully
    asks a question, whether to do the "some operation"

    thanks

  6. Re: yes with xargs

    In article <3bb94009-cc33-4238-9186-ea55e5aa5374@t41g2000hsc.googlegroups.com>,
    sinbad wrote:

    >No that's not what i am looking for
    > # showcheckout | xargs -n1 "some operation" | yes
    >
    >Here the "some operation" is going to ask a question,not the
    >showcheckout, for which i have to answer yes.
    >showcheckout simply lists the files, which have to be fed as input for
    >"some operation" which will actaully
    >asks a question, whether to do the "some operation"


    I suspect that xargs may not actually be the right tool for the job.
    Try this (if you're using a sh-family shell; I'm not sure what the
    corresponding csh-family syntax is):
    --------
    for f in `showcheckout`; do yes | some-operation $f; done
    --------

    If you really want to use xargs, you can use it to invoke a very small
    shell script that looks something like:
    --------
    #!/bin/sh
    yes | some-operation $*
    --------
    but I don't think xargs will set up the pipeline for you, which it
    would have to do to make this work entirely from the command line.


    dave

    --
    Dave Vandervies dj3vande at eskimo dot com
    You will probably find those sites equally silent on the concept of a
    program losing hit points every time it invokes undefined behavior
    --Gordon Burditt in comp.lang.c

  7. Re: yes with xargs

    sinbad writes:

    > No that's not what i am looking for
    > # showcheckout | xargs -n1 "some operation" | yes
    >
    > Here the "some operation" is going to ask a question,not the
    > showcheckout, for which i have to answer yes.
    > showcheckout simply lists the files, which have to be fed as input for
    > "some operation" which will actaully
    > asks a question, whether to do the "some operation"


    Ah, I think I understand now.

    There is probably a way to do this with some elaborate redirections.
    Easier might be to use a FIFO.

    mkfifo myfifo
    showcheckout >myfifo &
    yes | xargs -a myfifo -n1 "some operation"




  8. Re: yes with xargs

    >No that's not what i am looking for
    > # showcheckout | xargs -n1 "some operation" | yes
    >
    >Here the "some operation" is going to ask a question,not the
    >showcheckout, for which i have to answer yes.


    Unfortunately, you can't use stdin for two different things at once:
    the list of files for xargs, and the answers to the questions
    for the commands run by xargs.

    >showcheckout simply lists the files, which have to be fed as input for
    >"some operation" which will actaully
    >asks a question, whether to do the "some operation"
    >
    >thanks




  9. Re: yes with xargs

    On Oct 20, 6:20 pm, dj3va...@csclub.uwaterloo.ca.invalid wrote:
    > In article
    > <3bb94009-cc33-4238-9186-ea55e5aa5...@t41g2000hsc.googlegroups.com>,


    > sinbad wrote:
    > >No that's not what i am looking for
    > > # showcheckout | xargs -n1 "some operation" | yes


    > >Here the "some operation" is going to ask a question,not the
    > >showcheckout, for which i have to answer yes.
    > >showcheckout simply lists the files, which have to be fed as input for
    > >"some operation" which will actaully
    > >asks a question, whether to do the "some operation"


    > I suspect that xargs may not actually be the right tool for
    > the job. Try this (if you're using a sh-family shell; I'm not
    > sure what the corresponding csh-family syntax is):
    > --------
    > for f in `showcheckout`; do yes | some-operation $f; done
    > --------


    Since some-operation can apparently take multiple filenames
    (otherwise, xargs wouldn't work), he could also simply use:

    yes | some-operation ` showcheckout `

    This will fail if the output of showcheckout is too long, but on
    modern systems, "too long" can easily be in the megabyte range.

    > If you really want to use xargs, you can use it to invoke a
    > very small shell script that looks something like:
    > --------
    > #!/bin/sh
    > yes | some-operation $*
    > --------
    > but I don't think xargs will set up the pipeline for you,
    > which it would have to do to make this work entirely from the
    > command line.


    It won't. Also, I don't think it can invoke shell builtins or
    functions; certainly not functions defined in your shell script,
    in any case.

    --
    James Kanze (GABI Software) email:james.kanze@gmail.com
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

  10. Re: yes with xargs

    On Mon, 2008-10-20 at 04:06 -0700, sinbad wrote:
    > On Oct 20, 10:42 am, Nate Eldredge wrote:
    > > sinbad writes:

    [...]
    > >
    > > > showcheckout --> it lists all checkout files, Now for each of the
    > > > file, I need to some operation, This operations ask for Yes/No Q;
    > > > so i tried the following, both didn't work

    > >
    > > > # showcheckout | yes| xargs -n1 "some operation"

    > >

    [...]
    > >
    > > I think what you want is
    > >
    > > yes | showcheckout
    > >
    > > This sends the output of yes into the input of showcheckout, which is
    > > likely where it expects to get the answers to its prompts. So it should
    > > have the effect of answering "y" to every question.
    > >
    > > xargs is useful when you need to use a file or the output of a command
    > > as *command line arguments* to another command. I don't think that's
    > > what you're looking for here.

    >
    > No that's not what i am looking for
    > # showcheckout | xargs -n1 "some operation" | yes
    >
    > Here the "some operation" is going to ask a question,not the
    > showcheckout, for which i have to answer yes.
    > showcheckout simply lists the files, which have to be fed as input for
    > "some operation" which will actaully
    > asks a question, whether to do the "some operation"
    >


    what about:
    $ slowcheckout | xargs -n1 sh -c 'yes | some_operation'

    You can use the shell variable $0 in some_operation to get the name of
    the file to work on.

    I did a simple test that seems to work:

    $ ls *.test | xargs -n1 sh -c 'yes | rm -i $0'
    rm: remove regular file `bar.test'? rm: remove regular file `baz.test'?
    rm: remove regular file `foo.test'?

    John




+ Reply to Thread