Re: User function in pipe
- From: Kevin Collins <spamtotrash@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 29 Dec 2005 18:50:16 GMT
In article <1135868226.745428.71710@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, shima 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 ...
> BR
> Shima
In this particular case, why not just make your function:
reversed()
{
sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'`
}
The sed command is already a filter, so it will continue to be one:
echo ${text} | reverse
Kevin
--
Unix Guy Consulting, LLC
Unix and Linux Automation, Shell, Perl and CGI scripting
http://www.unix-guy.com
.
- 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: variable name conventions (caps vs. lower-case)
- Next by Date: pdksh command line editing
- Previous by thread: Re: User function in pipe
- Next by thread: Re: User function in pipe
- Index(es):
Relevant Pages
|