Re: User function in pipe
- From: "Stachu 'Dozzie' K." <dozzie@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 29 Dec 2005 15:23:22 +0000 (UTC)
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
.
- Follow-Ups:
- Re: User function in pipe
- From: shima
- Re: User function in pipe
- References:
- User function in pipe
- From: shima
- Re: User function in pipe
- From: Barry Margolin
- Re: User function in pipe
- From: shima
- Re: User function in pipe
- From: Stachu 'Dozzie' K.
- Re: User function in pipe
- From: shima
- User function in pipe
- Prev by Date: Re: User function in pipe
- Next by Date: Re: User function in pipe
- Previous by thread: Re: User function in pipe
- Next by thread: Re: User function in pipe
- Index(es):
Relevant Pages
|