Re: User function in pipe



On 29.12.2005, shima <shima@xxxxx> wrote:
>
> Stachu 'Dozzie' K. napisal(a):
>> On 29.12.2005, shima <shima@xxxxx> wrote:
>> >
>> > Barry Margolin napisal(a):
>> >
>> >> > echo ${text} | reverse | cut -f2- -d '/' | reverse
>> >> Shell functions access their arguments in the same way that scripts do,
>> >> with variables named $1, $2, etc.
>> >
>> > Yes, but using
>> > echo ${text} | reverse
>> >
>> > give me empty string.
>> > My function is:
>> > reverse()
>> > {
>> > effect= expression_to_do_sth_with ${1}
>> > echo ${effect} //return does not work, of course
>> > }
>> >
>> > What is wrong with my function?
>>
>> It's simple: Your function doesn't contain body.
>> Show the whole function, and then we could tell you something about it.
>> Otherwise we can just guess.
>
> AYW:
> reversed()
> {
> rever=`echo ${1} | sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'`
> echo ${rever}
> }
>
> I don't think it will help, but ...

OK, now I see where is the problem. Indeed it wasn't necessary to give
contents, but it helped me to understand your question.

Does your function read data from STDIN? You're trying to put all data
to its STDIN, not to parameters. Your function needs to be used as
`reversed xyz', not as `echo xyz | reversed'. $1 expands to first
parameter, not to first character/word/line/whatever from standard
input.

--
Feel free to correct my English
Stanislaw Klekot
.



Relevant Pages

  • Re: User function in pipe
    ... >> Stachu 'Dozzie' K. napisal: ... > Does your function read data from STDIN? ... How to rewrite 'reverse' to use it in a pipe? ...
    (comp.unix.shell)
  • Re: User function in pipe
    ... > Stachu 'Dozzie' K. napisal: ... >>> give me empty string. ... echo $| reverse ... Unix Guy Consulting, LLC ...
    (comp.unix.shell)
  • Re: User function in pipe
    ... But I need sth more ... > How to rewrite 'reverse' to use it in a pipe? ... "Arguments" are the parameters that appear after a command ... your function can get its stdin by using the "read" ...
    (comp.unix.shell)
  • Re: User function in pipe
    ... > How to rewrite 'reverse' to use it in a pipe? ... How to force function to ... To read from stdin, use the "read" command. ...
    (comp.unix.shell)
  • Re: trying to launch a second CGI, from a parent CGI
    ... > input at all from stdin? ... I think I posted this about the same time as the double reverse. ... Sinan Unur ... comp.lang.perl.misc guidelines on the WWW: ...
    (comp.lang.perl.misc)