Re: User function in pipe



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
.



Relevant Pages

  • Re: User function in pipe
    ... > Stachu 'Dozzie' K. napisal: ... >>> give me empty string. ... >>> reverse() ... Does your function read data from STDIN? ...
    (comp.unix.shell)
  • Win32::Console::ANSI messes up IO
    ... Works fine on Unix, so I was ... disappointed to discover that it didn't work on Windows because ... cmd.exe doesn't accept ANSI control codes. ... is there an alternative way of getting reverse video ...
    (comp.lang.perl.modules)
  • Re: Convert from UNIX time
    ... (Reverse address to reply.) ... I added two other colums z_opendate and z_closedate and I now would ... like to convert open_date and close_date from unix time and populate the new ... > Can anyone give me some insite on how to do this? ...
    (microsoft.public.sqlserver.programming)
  • Re: Unix equivalent of SYS$BINTIM ?
    ... I have found routines that get time from unix binary format to text ... format => asctime(), but haven't found the reverse. ... Is there one in Unix? ...
    (comp.os.vms)
  • Re: list of high profile linux users
    ... DC is using Windows and Unix - at least in Engineering. ... Alexander Skwar ... The reverse side also has a reverse side. ...
    (comp.os.linux.misc)